diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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 cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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 cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h new file mode 100644 index 0000000..79049a7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h @@ -0,0 +1,30 @@ +#ifndef SIGNALGENERATORZDATIMEDTO_H +#define SIGNALGENERATORZDATIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorZDATimeDto class + * 信号产生器 ZDA时间信息 + */ +class SignalGeneratorZDATimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorZDATimeDto(QObject *parent = nullptr); + + QString zdaTime; // <1> 时分秒 + QString zdaDay; // <2> 日期 + QString zdaMon; // <3> 月 + QString zdaYear; // <4> 年 + QString leapSec; // <5> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <6> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORZDATIMEDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h new file mode 100644 index 0000000..79049a7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h @@ -0,0 +1,30 @@ +#ifndef SIGNALGENERATORZDATIMEDTO_H +#define SIGNALGENERATORZDATIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorZDATimeDto class + * 信号产生器 ZDA时间信息 + */ +class SignalGeneratorZDATimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorZDATimeDto(QObject *parent = nullptr); + + QString zdaTime; // <1> 时分秒 + QString zdaDay; // <2> 日期 + QString zdaMon; // <3> 月 + QString zdaYear; // <4> 年 + QString leapSec; // <5> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <6> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORZDATIMEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..b9b2894 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "TimeSwitcherInterfaceDto.h" + +TimeSwitcherInterfaceDto::TimeSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h new file mode 100644 index 0000000..79049a7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h @@ -0,0 +1,30 @@ +#ifndef SIGNALGENERATORZDATIMEDTO_H +#define SIGNALGENERATORZDATIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorZDATimeDto class + * 信号产生器 ZDA时间信息 + */ +class SignalGeneratorZDATimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorZDATimeDto(QObject *parent = nullptr); + + QString zdaTime; // <1> 时分秒 + QString zdaDay; // <2> 日期 + QString zdaMon; // <3> 月 + QString zdaYear; // <4> 年 + QString leapSec; // <5> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <6> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORZDATIMEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..b9b2894 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "TimeSwitcherInterfaceDto.h" + +TimeSwitcherInterfaceDto::TimeSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h new file mode 100644 index 0000000..11e4b53 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef TIMESWITCHERINTERFACEDTO_H +#define TIMESWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class TimeSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // TIMESWITCHERINTERFACEDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h new file mode 100644 index 0000000..79049a7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h @@ -0,0 +1,30 @@ +#ifndef SIGNALGENERATORZDATIMEDTO_H +#define SIGNALGENERATORZDATIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorZDATimeDto class + * 信号产生器 ZDA时间信息 + */ +class SignalGeneratorZDATimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorZDATimeDto(QObject *parent = nullptr); + + QString zdaTime; // <1> 时分秒 + QString zdaDay; // <2> 日期 + QString zdaMon; // <3> 月 + QString zdaYear; // <4> 年 + QString leapSec; // <5> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <6> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORZDATIMEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..b9b2894 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "TimeSwitcherInterfaceDto.h" + +TimeSwitcherInterfaceDto::TimeSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h new file mode 100644 index 0000000..11e4b53 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef TIMESWITCHERINTERFACEDTO_H +#define TIMESWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class TimeSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // TIMESWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp new file mode 100644 index 0000000..1cad164 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp @@ -0,0 +1,65 @@ +#include "TimeSwitcherStatusDto.h" + +TimeSwitcherStatusDto::TimeSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("refTmSrc", refTmSrc); + dataObj.insert("oppsPhaseAccOut", oppsPhaseAccOut); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + QJsonArray tmSrcStatusArray; + QJsonArray tmSrcStatusStrArray; + QJsonArray localTmDiffArray; + QJsonArray delayCompensArray; + QJsonArray oppsOutStatusArray; + QJsonArray bdcOutStatusArray; + QJsonArray bacOutStatusArray; + for (int i = 0; i < 5; i++) + { + tmSrcStatusArray.append(tmSrcStatusList.at(i)); + QString tmSrcStatus = tmSrcStatusList.at(i); + if (tmSrcStatus.length() == 3) + { + QString tmSrcStatusStr = ""; + for (int j = 0; j < 3; j++) + { + if (tmSrcStatus.mid(j, 1) == '1') + { + tmSrcStatusStr += tmSrcStr[j] + ","; + } + } + tmSrcStatusStrArray.append(tmSrcStatusStr.mid(0, tmSrcStatusStr.length() - 1)); + } else + { + tmSrcStatusStrArray.append(""); + } + localTmDiffArray.append(localTmDiffList.at(i)); + delayCompensArray.append(delayCompensList.at(i)); + oppsOutStatusArray.append(oppsOutStatusList.at(i)); + bdcOutStatusArray.append(bdcOutStatusList.at(i)); + bacOutStatusArray.append(bacOutStatusList.at(i)); + } + dataObj.insert("tmSrcStatusArray", tmSrcStatusArray); + dataObj.insert("tmSrcStatusStrArray", tmSrcStatusStrArray); + dataObj.insert("localTmDiffArray", localTmDiffArray); + dataObj.insert("delayCompensArray", delayCompensArray); + dataObj.insert("oppsOutStatusArray", oppsOutStatusArray); + dataObj.insert("bdcOutStatusArray", bdcOutStatusArray); + dataObj.insert("bacOutStatusArray", bacOutStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h new file mode 100644 index 0000000..79049a7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h @@ -0,0 +1,30 @@ +#ifndef SIGNALGENERATORZDATIMEDTO_H +#define SIGNALGENERATORZDATIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorZDATimeDto class + * 信号产生器 ZDA时间信息 + */ +class SignalGeneratorZDATimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorZDATimeDto(QObject *parent = nullptr); + + QString zdaTime; // <1> 时分秒 + QString zdaDay; // <2> 日期 + QString zdaMon; // <3> 月 + QString zdaYear; // <4> 年 + QString leapSec; // <5> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <6> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORZDATIMEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..b9b2894 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "TimeSwitcherInterfaceDto.h" + +TimeSwitcherInterfaceDto::TimeSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h new file mode 100644 index 0000000..11e4b53 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef TIMESWITCHERINTERFACEDTO_H +#define TIMESWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class TimeSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // TIMESWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp new file mode 100644 index 0000000..1cad164 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp @@ -0,0 +1,65 @@ +#include "TimeSwitcherStatusDto.h" + +TimeSwitcherStatusDto::TimeSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("refTmSrc", refTmSrc); + dataObj.insert("oppsPhaseAccOut", oppsPhaseAccOut); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + QJsonArray tmSrcStatusArray; + QJsonArray tmSrcStatusStrArray; + QJsonArray localTmDiffArray; + QJsonArray delayCompensArray; + QJsonArray oppsOutStatusArray; + QJsonArray bdcOutStatusArray; + QJsonArray bacOutStatusArray; + for (int i = 0; i < 5; i++) + { + tmSrcStatusArray.append(tmSrcStatusList.at(i)); + QString tmSrcStatus = tmSrcStatusList.at(i); + if (tmSrcStatus.length() == 3) + { + QString tmSrcStatusStr = ""; + for (int j = 0; j < 3; j++) + { + if (tmSrcStatus.mid(j, 1) == '1') + { + tmSrcStatusStr += tmSrcStr[j] + ","; + } + } + tmSrcStatusStrArray.append(tmSrcStatusStr.mid(0, tmSrcStatusStr.length() - 1)); + } else + { + tmSrcStatusStrArray.append(""); + } + localTmDiffArray.append(localTmDiffList.at(i)); + delayCompensArray.append(delayCompensList.at(i)); + oppsOutStatusArray.append(oppsOutStatusList.at(i)); + bdcOutStatusArray.append(bdcOutStatusList.at(i)); + bacOutStatusArray.append(bacOutStatusList.at(i)); + } + dataObj.insert("tmSrcStatusArray", tmSrcStatusArray); + dataObj.insert("tmSrcStatusStrArray", tmSrcStatusStrArray); + dataObj.insert("localTmDiffArray", localTmDiffArray); + dataObj.insert("delayCompensArray", delayCompensArray); + dataObj.insert("oppsOutStatusArray", oppsOutStatusArray); + dataObj.insert("bdcOutStatusArray", bdcOutStatusArray); + dataObj.insert("bacOutStatusArray", bacOutStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeSwitcherStatusDto.h b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.h new file mode 100644 index 0000000..3862cc4 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.h @@ -0,0 +1,33 @@ +#ifndef TIMESWITCHERSTATUSDTO_H +#define TIMESWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class TimeSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeSwitcherStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> + QString refSelectType; // <2> + QString refTmSrc; // <3> + QList tmSrcStatusList; // <4-8> + QList localTmDiffList; // <9-13> + qlonglong oppsPhaseAccOut; // <14> + qint8 bacRatio; // <15> B-AC调制比,2~6 + float bacRange; // <16> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + QList delayCompensList; // <17-22> + QList oppsOutStatusList; // <23> + QList bdcOutStatusList; // <24> + QList bacOutStatusList; // <25> + + QJsonObject toJSON(); + +private: + const QString tmSrcStr[3] = {"1PPS", "B-DC", "B-AC"}; +}; + +#endif // TIMESWITCHERSTATUSDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index cdd570d..3f17e33 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -19,14 +19,20 @@ SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp +SOURCES += TimeSwitcherForm.cpp +SOURCES += FreqSwitcherForm.cpp HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h +HEADERS += TimeSwitcherForm.h +HEADERS += FreqSwitcherForm.h FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui +FORMS += TimeSwitcherForm.ui +FORMS += FreqSwitcherForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 56291ba..e02df0f 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -35,12 +35,20 @@ signGenForm = new SignalGeneratorForm(this); ui->stackedWidget->addWidget(signGenForm); + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + + // kafka consumer kafkaConsumer = new QKafkaConsumer(this); kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); kafkaConsumer->createConsumer(); kafkaConsumer->start(); + // init device type and device list httpReq = new HttpRequestController(this); // 1. 获取访问接口需要的token int retCode = this->initHttpToken(); @@ -92,13 +100,13 @@ 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 }); -// } + // 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 }); + } } void DeviceHubWindow::on_devSelect_currentIndexChanged(int index) @@ -131,13 +139,13 @@ } } -// // 5. 设置下拉框的样式 + // 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 }); -// } + for (int i = 0; i < model->rowCount(); ++i) + { + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); + } // ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 9b9cd91..94bf742 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -9,6 +9,8 @@ #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" +#include "TimeSwitcherForm.h" +#include "FreqSwitcherForm.h" QT_BEGIN_NAMESPACE namespace Ui { class DeviceHubWindow; } @@ -34,6 +36,8 @@ // forms FrequencyTuningForm * freqTunForm; SignalGeneratorForm * signGenForm; + TimeSwitcherForm * tmSwitForm; + FreqSwitcherForm * freqSwitForm; private slots: void on_minButt_clicked(); diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp new file mode 100644 index 0000000..e988bcf --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -0,0 +1,84 @@ +#include "FreqSwitcherForm.h" +#include "ui_FreqSwitcherForm.h" +#include "DeviceHubWindow.h" + +FreqSwitcherForm::FreqSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::FreqSwitcherForm) +{ + ui->setupUi(this); +} + +FreqSwitcherForm::~FreqSwitcherForm() +{ + delete ui; +} + +void FreqSwitcherForm::on_freqSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); + device->mockReceivData(); +} + +void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0601") + { + FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0602") + { + FreqSwitcherInterfaceDto * interFrameDto = (FreqSwitcherInterfaceDto *) frameData; + + } +} + +void FreqSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,09") + { + + } else if (commandType == "GLF,12") + { + + } else if (commandType == "GLF,17") + { + + } else if (commandType == "GLF,20") + { + + } else if (commandType == "GLF,21") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/FreqSwitcherForm.h b/DeviceHub/FreqSwitcherForm.h new file mode 100644 index 0000000..5b53332 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef FREQSWITCHERFORM_H +#define FREQSWITCHERFORM_H + +#include +#include "device/FreqSwitcher.h" + +namespace Ui { +class FreqSwitcherForm; +} + +class FreqSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit FreqSwitcherForm(QWidget *parent = nullptr); + ~FreqSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_freqSwiButt_clicked(); + +private: + Ui::FreqSwitcherForm *ui; +}; + +#endif // FREQSWITCHERFORM_H diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui new file mode 100644 index 0000000..e6e98a7 --- /dev/null +++ b/DeviceHub/FreqSwitcherForm.ui @@ -0,0 +1,99 @@ + + + FreqSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock FreqSwitcher + + + + + + 100 + 120 + 50 + 30 + + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index c440419..3bd9184 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -22,12 +22,6 @@ 40 - - - 微软雅黑 - 10 - - Mock FrequencyTuning diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 698ec36..8961771 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -1,5 +1,6 @@ #include "SignalGeneratorForm.h" #include "ui_SignalGeneratorForm.h" +#include "DeviceHubWindow.h" SignalGeneratorForm::SignalGeneratorForm(QWidget *parent) : QWidget(parent), @@ -12,3 +13,121 @@ { delete ui; } + +void SignalGeneratorForm::on_sigGenButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); + device->mockReceivData(); +} + +void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0401") + { + SignalGeneratorInterfaceDto * interFrameDto = (SignalGeneratorInterfaceDto *) frameData; + ui->sgKeyControl->setText(interFrameDto->keyControl == "1" ? "锁定" : "解锁"); + ui->sgTimeType->setText(interFrameDto->timeType == "1" ? "儒略日" : "年月日"); + } else if (frameData->frameType == "0402") + { + SignalGeneratorStatusDto * statusFrameDto = (SignalGeneratorStatusDto *) frameData; + ui->sgDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常"); + ui->sgLeapSec->setText(statusFrameDto->leapSec == "2" ? "负闰秒" : (statusFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgLeapTimestamp->setText(statusFrameDto->leapTimestamp); + ui->sgFreqSignalStatus->setText(statusFrameDto->devStatus == "1" ? "有效" : "无效"); + ui->sgFreqSignalType->setText(statusFrameDto->freqSignalType == "1" ? "5MHz" : "10MHz"); + ui->sgOppsSignalStatus->setText(statusFrameDto->oppsSignalStatus == "1" ? "有效" : "无效"); + ui->sgPhaseDiff->setText(QString("%1 ns").arg(statusFrameDto->phaseDiff)); + ui->sgPulseWidth->setText(QString("%1 ns").arg(statusFrameDto->pulseWidth)); + ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); + ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); + ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + } else if (frameData->frameType == "0403") + { + SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; + ui->sgMJDTime->setText(mjdFrameDto->mjdTime); + ui->sgMJDDate->setText(mjdFrameDto->mjdDay); + ui->sgMJDLeapSec->setText(mjdFrameDto->leapSec == "2" ? "负闰秒" : (mjdFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgMJDValid->setText(mjdFrameDto->valid == "01" ? "有效" : "无效"); + } else if (frameData->frameType == "0404") + { + SignalGeneratorZDATimeDto * zdaFrameDto = (SignalGeneratorZDATimeDto *) frameData; + ui->sgZDATime->setText(zdaFrameDto->zdaTime); + ui->sgZDADate->setText(zdaFrameDto->zdaYear + "-" + zdaFrameDto->zdaMon + "-" + zdaFrameDto->zdaDay); + ui->sgZDALeapSec->setText(zdaFrameDto->leapSec == "2" ? "负闰秒" : (zdaFrameDto->leapSec == "1" ? "正闰秒" : "无闰秒")); + ui->sgZDAValid->setText(zdaFrameDto->valid == "01" ? "有效" : "无效"); + } +} + +void SignalGeneratorForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + ui->sgLeapSecondSet->setText(command.value("params").toString()); + ui->sgLeapSecondSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,02") + { + ui->sgSingleSynchSet->setText(command.value("params").toString()); + ui->sgSingleSynchSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,03") + { + ui->sgDateSet->setText(command.value("params").toString()); + ui->sgDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,04") + { + ui->sgSecondWidthSet->setText(command.value("params").toString()); + ui->sgSecondWidthSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,05") + { + ui->sgBacRatioSet->setText(command.value("params").toString()); + ui->sgBacRatioSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,06") + { + ui->sgBacRangeSet->setText(command.value("params").toString()); + ui->sgBacRangeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,07") + { + ui->sgOppsPhaseShiftSet->setText(command.value("params").toString()); + ui->sgOppsPhaseShiftSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,08") + { + ui->sgLeapTimestampSet->setText(command.value("params").toString()); + ui->sgLeapTimestampSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,09") + { + ui->sgMJDDateSet->setText(command.value("params").toString()); + ui->sgMJDDateSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLF,10") + { + ui->sgTimeSet->setText(command.value("params").toString()); + ui->sgTimeSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,01") + { + ui->sgKeyControlSet->setText(command.value("params").toString()); + ui->sgKeyControlSetRaw->setText(command.value("rawCommand").toString()); + } else if (commandType == "GLC,02") + { + ui->sgTimeTypeSet->setText(command.value("params").toString()); + ui->sgTimeTypeSetRaw->setText(command.value("rawCommand").toString()); + } +} diff --git a/DeviceHub/SignalGeneratorForm.h b/DeviceHub/SignalGeneratorForm.h index 0abdeec..9b06168 100644 --- a/DeviceHub/SignalGeneratorForm.h +++ b/DeviceHub/SignalGeneratorForm.h @@ -2,6 +2,7 @@ #define SIGNALGENERATORFORM_H #include +#include "device/SignalGenerator.h" namespace Ui { class SignalGeneratorForm; @@ -15,6 +16,13 @@ explicit SignalGeneratorForm(QWidget *parent = nullptr); ~SignalGeneratorForm(); +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_sigGenButt_clicked(); + private: Ui::SignalGeneratorForm *ui; }; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index e060a66..edd892e 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -6,1385 +6,1385 @@ 0 0 - 400 - 300 + 1200 + 700 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 - - - + + + + 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/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp new file mode 100644 index 0000000..a7d4b2f --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.cpp @@ -0,0 +1,81 @@ +#include "TimeSwitcherForm.h" +#include "ui_TimeSwitcherForm.h" +#include "DeviceHubWindow.h" + +TimeSwitcherForm::TimeSwitcherForm(QWidget *parent) : + QWidget(parent), + ui(new Ui::TimeSwitcherForm) +{ + ui->setupUi(this); +} + +TimeSwitcherForm::~TimeSwitcherForm() +{ + delete ui; +} + +void TimeSwitcherForm::on_tmSwiButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeSwitcher * device = (TimeSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("05").at(devIndex); + device->mockReceivData(); +} + +void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) +{ + // 当前显示的设备编号 + if (frameData->frameType == "0501") + { + TimeSwitcherStatusDto * statusFrameDto = (TimeSwitcherStatusDto *) frameData; + + } else if (frameData->frameType == "0502") + { + TimeSwitcherInterfaceDto * interFrameDto = (TimeSwitcherInterfaceDto *) frameData; + + } +} + +void TimeSwitcherForm::displayDeviceCommandOnForm(QJsonObject command) +{ + QString deviceId = command.value("deviceId").toString(); + QList typeDevList = ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04"); + for (int i = 0; i < ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->count(); i++) + { + if (((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->itemData(i) == "04") + { + ((DeviceHubWindow *)this->parent()->parent())->getDevTypeSelect()->setCurrentIndex(i); + } + } + for (int i = 0; i < typeDevList.size(); i++) + { + if (typeDevList.at(i)->getDeviceId() == command.value("deviceId").toString()) + { + ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->setCurrentIndex(i); + } + } + + QString commandType = command.value("command").toString(); + if (commandType == "GLF,01") + { + + } else if (commandType == "GLF,02") + { + + } else if (commandType == "GLF,03") + { + + } else if (commandType == "GLF,04") + { + + } else if (commandType == "GLF,05") + { + + } else if (commandType == "GLF,06") + { + + } else if (commandType == "GLC,01") + { + + } +} diff --git a/DeviceHub/TimeSwitcherForm.h b/DeviceHub/TimeSwitcherForm.h new file mode 100644 index 0000000..aaa1e04 --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.h @@ -0,0 +1,30 @@ +#ifndef TIMESWITCHERFORM_H +#define TIMESWITCHERFORM_H + +#include +#include "device/TimeSwitcher.h" + +namespace Ui { +class TimeSwitcherForm; +} + +class TimeSwitcherForm : public QWidget +{ + Q_OBJECT + +public: + explicit TimeSwitcherForm(QWidget *parent = nullptr); + ~TimeSwitcherForm(); + +public slots: + void drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData); + void displayDeviceCommandOnForm(QJsonObject command); + +private slots: + void on_tmSwiButt_clicked(); + +private: + Ui::TimeSwitcherForm *ui; +}; + +#endif // TIMESWITCHERFORM_H diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui new file mode 100644 index 0000000..2a428fc --- /dev/null +++ b/DeviceHub/TimeSwitcherForm.ui @@ -0,0 +1,157 @@ + + + TimeSwitcherForm + + + + 0 + 0 + 1200 + 600 + + + + Form + + + + + 50 + 20 + 180 + 40 + + + + Mock TimeSwitcher + + + + + + 20 + 80 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 工作状态 + + + + + + 20 + 230 + 100 + 30 + + + + + 微软雅黑 + 12 + + + + 参数设置 + + + + + + 20 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 设备工作状态 + + + + + + 100 + 120 + 50 + 30 + + + + + + + 380 + 120 + 50 + 30 + + + + + + + 170 + 120 + 60 + 30 + + + + + 微软雅黑 + 10 + + + + 闰秒标志 + + + + + + 230 + 120 + 50 + 30 + + + + + + + 300 + 120 + 80 + 30 + + + + + 微软雅黑 + 10 + + + + 频率信号状态 + + + + + + diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index ede187f..2d9d345 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,5 +1,9 @@ #include "DeviceBase.h" #include "FrequencyTuning.h" +#include "SignalGenerator.h" +#include "TimeSwitcher.h" +#include "FreqSwitcher.h" + #include DeviceBase::DeviceBase(QObject *parent) : QObject(parent) @@ -38,7 +42,15 @@ if (deviceType == "03") { base = new FrequencyTuning(parent); - base->devType = "03"; + } else if (deviceType == "04") + { + base = new SignalGenerator(parent); + } else if (deviceType == "05") + { + base = new TimeSwitcher(parent); + } else if (deviceType == "06") + { + base = new FreqSwitcher(parent); } return base; diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8341091..8a3b271 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -2,7 +2,6 @@ #define DEVICEBASE_H #include -//#include "FrequencyTuning.h" #include "common/utils/QSerialPortUtil.h" #include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 57b440d..96ce66a 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -1,18 +1,27 @@ #include "FreqSwitcher.h" - +#include "DeviceHubWindow.h" #include #include FreqSwitcher::FreqSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &FreqSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); + connect(this, &FreqSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &FreqSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } FreqSwitcher::~FreqSwitcher() @@ -21,6 +30,18 @@ this, &FreqSwitcher::dataReceivedHandler); } +void FreqSwitcher::mockReceivData() +{ + QByteArray buffer; + + // freq switcher + buffer.append("$GLF,0,4,0,0,22000,-745,-776,0,0,0,0,0,100,100,0,0,0,1,00000,111111,111111*54").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLN,0,192.168.000.123,255.255.255.000,192.168.000.001,192.168.001.123,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +50,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +59,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,14 +92,84 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } +void FreqSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void FreqSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 67f06f8..fd19204 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/FreqSwitcherProtocolBM.h" +#include "protocol/dto/FreqSwitcherInterfaceDto.h" +#include "protocol/dto/FreqSwitcherStatusDto.h" class FreqSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; #endif // FREQSWITCHER_H diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index ffce052..e2038c2 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -154,7 +154,7 @@ QString date = now.toString("yyyy-MM-dd"); // 1. 原始字节数组数据 - QString filename = "command_" + devCode + ".log"; + QString filename = "frame_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index b6be288..e99ddc1 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -1,18 +1,27 @@ #include "SignalGenerator.h" - +#include "DeviceHubWindow.h" #include #include SignalGenerator::SignalGenerator(QObject *parent) : DeviceBase(parent) { + this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(this, &SignalGenerator::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); + connect(this, &SignalGenerator::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::displayDeviceCommandOnForm); + + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &SignalGenerator::commandReceivedHandler); + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); kafkaProducer.createProducer(); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } SignalGenerator::~SignalGenerator() @@ -21,6 +30,20 @@ this, &SignalGenerator::dataReceivedHandler); } +void SignalGenerator::mockReceivData() +{ + QByteArray buffer; + + // signal generator + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + buffer.append("$GLF,1,0,20210929,1,1,1,-0.01,20000,0,2,50,1*48").append("\r\n"); + buffer.append("$GPZDA,192157.00,01,01,2000,0,01*5C").append("\r\n"); + buffer.append("$GPMJD,192157.00,51544,0,01*73").append("\r\n"); + buffer.append("$GLC,0,0*48").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void SignalGenerator::dataReceivedHandler(QByteArray data) { @@ -30,6 +53,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -37,27 +62,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * sgFrameDto = protocol->frameFactory(frameType); - if (sgFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, sgFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - sgFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - sgFrameDto->milisecond = now.toMSecsSinceEpoch(); - sgFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(sgFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete sgFrameDto; + delete frameDto; } } } @@ -68,12 +95,82 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); +} + +void SignalGenerator::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void SignalGenerator::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); } diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 6bae208..b000e8c 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -4,7 +4,10 @@ #include #include "device/DeviceBase.h" -//#include "protocol/SignalGeneratorProtocolBM.h" +#include "protocol/dto/SignalGeneratorInterfaceDto.h" +#include "protocol/dto/SignalGeneratorStatusDto.h" +#include "protocol/dto/SignalGeneratorMJDTimeDto.h" +#include "protocol/dto/SignalGeneratorZDATimeDto.h" class SignalGenerator : public DeviceBase { @@ -13,13 +16,18 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index ecf4d5a..f4c772e 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -1,18 +1,27 @@ #include "TimeSwitcher.h" - +#include "DeviceHubWindow.h" #include #include TimeSwitcher::TimeSwitcher(QObject *parent) : DeviceBase(parent) { + this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + connect(this, &TimeSwitcher::sendDataToDraw, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); + connect(this, &TimeSwitcher::sendCommandToDisplay, + ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::displayDeviceCommandOnForm); - this->protocol = DeviceStatusProtocolBase::deviceStatusProtocolFactory(typeid (this).name()); + connect(((DeviceHubWindow *)this->parent())->kafkaConsumer, &QKafkaConsumer::messageRecieved, + this, &TimeSwitcher::commandReceivedHandler); + + kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); + kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); + kafkaProducer.createProducer(); + + this->protocol = DeviceProtocolBase::deviceProtocolFactory(typeid (this).name()); } TimeSwitcher::~TimeSwitcher() @@ -21,6 +30,19 @@ this, &TimeSwitcher::dataReceivedHandler); } +void TimeSwitcher::mockReceivData() +{ + QByteArray buffer; + + // time switcher + buffer.append("$GPZDA,211219.00,01,01,2000,0,01*5D").append("\r\n"); + buffer.append("$GLC,0*54").append("\r\n"); + buffer.append("$GLF,1,1,1,010,100,100,000,000,0,-235136964.75,-235136959.89,0,0,0,5,50,-16390,-16710,-15660,-16700,-17300,11111,11111,11111*51").append("\r\n"); + buffer.append("$GLN,0,192.168.000.126,255.255.255.000,192.168.000.001,192.168.001.126,255.255.255.000,192.168.001.001,255.255.255.255,3000,2000,2001*75").append("\r\n"); + + this->dataReceivedHandler(buffer); +} + void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); @@ -29,6 +51,8 @@ QList frameList = protocol->extractFrameList(this->dataBuff); + this->dataBuff.clear(); + if (frameList.size() > 0) { for (int i = 0; i < frameList.size(); i++) @@ -36,27 +60,29 @@ QByteArray frameByte = frameList.at(i); int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * tsFrameDto = protocol->frameFactory(frameType); - if (tsFrameDto != nullptr) + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) { // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, tsFrameDto, frameType); + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); // 解析成功 if (parse == true) { QDateTime now = QDateTime::currentDateTime(); - tsFrameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - tsFrameDto->milisecond = now.toMSecsSinceEpoch(); - tsFrameDto->rawFrame = frameByte; + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; - this->afterFramePhase(tsFrameDto); + frameDto->devCode = devCode; + + this->afterFramePhase(frameDto); } // 在此处释放内存,不影响后续显示 // 不在此处释放内存则会导致内存持续增加 // 具体原因不明 - delete tsFrameDto; + delete frameDto; } } } @@ -67,12 +93,83 @@ std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << frameDto->rawFrame.toStdString() << std::endl; + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + // 3. 输出到中间件,执行后续处理过程 if (SettingConfig::getInstance().NEED_KAFKA == 1) { QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } + + // 4. 在界面上简单显示相差数据结果 + emit this->sendDataToDraw(frameDto); } + +void TimeSwitcher::sendDataToSerial(QByteArray data) +{ + data.append(FRAME_TAIL); + this->serialUtil.sendData(data); + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); +} + +void TimeSwitcher::commandReceivedHandler(QJsonObject command) +{ + if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") + { + std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) + { + std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; + return; + } + + // 记录日志 + // 0. 输出到日志文件中 + QDateTime now = QDateTime::currentDateTime(); + QString date = now.toString("yyyy-MM-dd"); + + // 1. 原始字节数组数据 + QString filename = "frame_" + devCode + ".log"; + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QLogUtil::writeChannelDataLogByDate(date, filename, content); + + QByteArray commandBytes = protocol->generateSettingCommand(command.value("command").toString(), command.value("params").toString()); + this->sendDataToSerial(commandBytes); + command.insert("rawCommand", QString::fromUtf8(commandBytes)); + + QJsonObject cmdcb; + cmdcb.insert("commandId", command.value("commandId").toString()); + cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes)); + cmdcb.insert("status", "1"); + this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact))); + + // display on page + emit sendCommandToDisplay(command); +} + diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 0ac7e3a..ad8eda7 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -4,7 +4,8 @@ #include #include "device/DeviceBase.h" -#include "protocol/TimeSwitcherProtocolBM.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" class TimeSwitcher : public DeviceBase { @@ -13,13 +14,18 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void afterFramePhase(DeviceFrameBaseDto * frameDto); + void mockReceivData() override; + + void afterFramePhase(DeviceFrameBaseDto * frameDto) override; + void sendDataToSerial(QByteArray data) override; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); + void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); + void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index bf56460..5ad8604 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/FrequencyTuning.h -#HEADERS += $$PWD/TimeSwitcher.h -#HEADERS += $$PWD/FreqSwitcher.h +HEADERS += $$PWD/SignalGenerator.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/FrequencyTuning.cpp -#SOURCES += $$PWD/TimeSwitcher.cpp -#SOURCES += $$PWD/FreqSwitcher.cpp +SOURCES += $$PWD/SignalGenerator.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/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index ca44773..4303ba6 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -1,6 +1,6 @@ #include "DeviceProtocolBase.h" #include "FrequencyTuningProtocolBM.h" -//#include "SignalGeneratorProtocolBM.h" +#include "SignalGeneratorProtocolBM.h" //#include "TimeSwitcherProtocolBM.h" //#include "FreqSwitcherProtocolBM.h" @@ -20,6 +20,9 @@ if (deviceType == "03") { return new FrequencyTuningProtocolBM(); + } else if (deviceType == "04") + { + return new SignalGeneratorProtocolBM(); } // if (deviceType.contains("SignalGenerator") == true) diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp new file mode 100644 index 0000000..359c0ce --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp @@ -0,0 +1,160 @@ +#include "FreqSwitcherProtocolBM.h" + +FreqSwitcherProtocolBM::FreqSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +FreqSwitcherProtocolBM::~FreqSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * FreqSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new FreqSwitcherInterfaceDto(); + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new FreqSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool FreqSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((FreqSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((FreqSwitcherInterfaceDto *)frameData)->frameType = FREQ_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case FreqSwitcherProtocolBM::FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((FreqSwitcherStatusDto *)frameData)->devStatus = subList.at(17); + ((FreqSwitcherStatusDto *)frameData)->lockPhaseType = subList.at(0); + ((FreqSwitcherStatusDto *)frameData)->digitalLockPhaseStatus = subList.at(1); + ((FreqSwitcherStatusDto *)frameData)->refSelectType = subList.at(2); + ((FreqSwitcherStatusDto *)frameData)->refFreqSrc = subList.at(3); + ((FreqSwitcherStatusDto *)frameData)->freqAdjustAcc = subList.at(10).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->phaseAdjustAcc = subList.at(11).toLongLong(); + for (int i = 0; i < 5; i++) + { + // + QString freqRefStatus = subList.at(4).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->freqRefStatusList.append(freqRefStatus); + + // + qlonglong localFreqDiff = subList.at(i + 5).toLongLong(); + ((FreqSwitcherStatusDto *)frameData)->localFreqDiffList.append(localFreqDiff); + + // + float freqRefWeight = subList.at(i + 12).toFloat(); + ((FreqSwitcherStatusDto *)frameData)->freqRefWeightList.append(freqRefWeight); + + // + QString inputFreqType = subList.at(18).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->inputFreqTypeList.append(inputFreqType); + } + + for (int i = 0; i < 6; i++) + { + // + QString outTenStatus = subList.at(19).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outTenStatusList.append(outTenStatus); + + // + QString outFiveStatus = subList.at(20).mid(i, 1); + ((FreqSwitcherStatusDto *)frameData)->outFiveStatusList.append(outFiveStatus); + } + + ((FreqSwitcherStatusDto *)frameData)->frameType = FREQ_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int FreqSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (FREQ_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (FREQ_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, FREQ_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < FREQ_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return FREQ_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return FREQ_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.h b/DeviceHub/protocol/FreqSwitcherProtocolBM.h new file mode 100644 index 0000000..fc4e8b7 --- /dev/null +++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef FREQSWITCHERPROTOCOLBM_H +#define FREQSWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/FreqSwitcherInterfaceDto.h" +#include "dto/FreqSwitcherStatusDto.h" + +class FreqSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit FreqSwitcherProtocolBM(QObject *parent = nullptr); + ~FreqSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum FREQ_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // FREQSWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp new file mode 100644 index 0000000..38929a3 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp @@ -0,0 +1,184 @@ +#include "SignalGeneratorProtocolBM.h" +#include + +SignalGeneratorProtocolBM::SignalGeneratorProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +SignalGeneratorProtocolBM::~SignalGeneratorProtocolBM() +{ + +} + +DeviceFrameBaseDto * SignalGeneratorProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * sgFrameData = 0; + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + sgFrameData = new SignalGeneratorInterfaceDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + sgFrameData = new SignalGeneratorStatusDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + sgFrameData = new SignalGeneratorZDATimeDto(); + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + sgFrameData = new SignalGeneratorMJDTimeDto(); + break; + + default: + sgFrameData = nullptr; + break; + } + + return sgFrameData; +} + +bool SignalGeneratorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME : + + ((SignalGeneratorInterfaceDto *)sgFrameData)->keyControl = subList.at(0); + ((SignalGeneratorInterfaceDto *)sgFrameData)->timeType = subList.at(1); + ((SignalGeneratorInterfaceDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_INTERFACE_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME : + + ((SignalGeneratorStatusDto *)sgFrameData)->devStatus = subList.at(0); + ((SignalGeneratorStatusDto *)sgFrameData)->leapSec = subList.at(1); + ((SignalGeneratorStatusDto *)sgFrameData)->leapTimestamp = subList.at(2); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalStatus = subList.at(3); + ((SignalGeneratorStatusDto *)sgFrameData)->freqSignalType = subList.at(4); + ((SignalGeneratorStatusDto *)sgFrameData)->oppsSignalStatus = subList.at(5); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseDiff = subList.at(6).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->pulseWidth = subList.at(7).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->phaseShiftAcc = subList.at(8).toLongLong(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRatio = subList.at(9).toUInt(); + ((SignalGeneratorStatusDto *)sgFrameData)->bacRange = subList.at(10).toFloat(); + ((SignalGeneratorStatusDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_STATUS_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME : + + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaTime = subList.at(0); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaDay = subList.at(1); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaMon = subList.at(2); + ((SignalGeneratorZDATimeDto *)sgFrameData)->zdaYear = subList.at(3); + ((SignalGeneratorZDATimeDto *)sgFrameData)->leapSec = subList.at(4); + ((SignalGeneratorZDATimeDto *)sgFrameData)->valid = subList.at(5); + ((SignalGeneratorZDATimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_ZDA_FRAME_TYPE; + break; + + case SignalGeneratorProtocolBM::SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME : + + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdTime = subList.at(0); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->mjdDay = subList.at(1); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->leapSec = subList.at(2); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->valid = subList.at(3); + ((SignalGeneratorMJDTimeDto *)sgFrameData)->frameType = SIGNAL_GENERATOR_MJD_FRAME_TYPE; + break; + + } + + return true; +} + +QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int SignalGeneratorProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_INTERFACE_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (SIGNAL_GENERATOR_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_STATUS_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::STATUS_FRAME; + } + } else if (SIGNAL_GENERATOR_MJD_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_MJD_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_MJD_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::MJD_FRAME; + } + } else if (SIGNAL_GENERATOR_ZDA_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, SIGNAL_GENERATOR_ZDA_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < SIGNAL_GENERATOR_ZDA_FRAME_MIN_LENGTH) + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::ZDA_FRAME; + } + } else + { + return SIGNAL_GENERATOR_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.h b/DeviceHub/protocol/SignalGeneratorProtocolBM.h new file mode 100644 index 0000000..04f3849 --- /dev/null +++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.h @@ -0,0 +1,40 @@ +#ifndef SIGNALGENERATORPROTOCOLBM_H +#define SIGNALGENERATORPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "dto/SignalGeneratorInterfaceDto.h" +#include "dto/SignalGeneratorStatusDto.h" +#include "dto/SignalGeneratorMJDTimeDto.h" +#include "dto/SignalGeneratorZDATimeDto.h" + +class SignalGeneratorProtocolBM : public DeviceProtocolBase +{ +public: + explicit SignalGeneratorProtocolBM(QObject *parent = nullptr); + ~SignalGeneratorProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * sgFrameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum SIGNAL_GENERATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + ZDA_FRAME = 3, + MJD_FRAME = 4, + NETWORK_FRAME = 5 + }; +}; + +#endif // SIGNALGENERATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp new file mode 100644 index 0000000..7691d83 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp @@ -0,0 +1,156 @@ +#include "TimeSwitcherProtocolBM.h" + +TimeSwitcherProtocolBM::TimeSwitcherProtocolBM(QObject *parent) : DeviceProtocolBase(parent) +{ + +} + +TimeSwitcherProtocolBM::~TimeSwitcherProtocolBM() +{ + +} + +DeviceFrameBaseDto * TimeSwitcherProtocolBM::frameFactory(int frameType) +{ + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + frameData = new TimeSwitcherInterfaceDto(); + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeSwitcherStatusDto(); + break; + + default: + frameData = nullptr; + break; + } + + return frameData; +} + +bool TimeSwitcherProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) +{ + // get the raw data between ',' and '*' + int start = rawData.indexOf(FRAME_CONTENT_SEP); + int end = rawData.indexOf(FRAME_SUM_SEP); + + QByteArray content = rawData.mid(start + 1, end - start - 1); + QString contentStr = QString(content); + QStringList subList = contentStr.split(","); + + switch (frameType) { + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME : + + ((TimeSwitcherInterfaceDto *)frameData)->ctrlStatus = subList.at(0); + ((TimeSwitcherInterfaceDto *)frameData)->frameType = TIME_SWITCHER_INTERFACE_FRAME_TYPE; + break; + + case TimeSwitcherProtocolBM::TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME : + + ((TimeSwitcherStatusDto *)frameData)->devStatus = subList.at(0); + ((TimeSwitcherStatusDto *)frameData)->refSelectType = subList.at(1); + ((TimeSwitcherStatusDto *)frameData)->refTmSrc = subList.at(2); + ((TimeSwitcherStatusDto *)frameData)->oppsPhaseAccOut = subList.at(13).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->bacRatio = subList.at(14).toInt(); + ((TimeSwitcherStatusDto *)frameData)->bacRange = subList.at(15).toFloat(); + for (int i = 0; i < 5; i++) + { + // + QString tmSrcStatus = subList.at(i + 3); + ((TimeSwitcherStatusDto *)frameData)->tmSrcStatusList.append(tmSrcStatus); + + // + double localTmDiff = subList.at(i + 8).toDouble(); + ((TimeSwitcherStatusDto *)frameData)->localTmDiffList.append(localTmDiff); + + // + qlonglong delayComp = subList.at(i + 16).toLongLong(); + ((TimeSwitcherStatusDto *)frameData)->delayCompensList.append(delayComp); + + // + QString oppsOutStatus = subList.at(21).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->oppsOutStatusList.append(oppsOutStatus); + + // + QString bdcOutStatus = subList.at(22).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bdcOutStatusList.append(bdcOutStatus); + + // + QString bacOutStatus = subList.at(23).mid(i, 1); + ((TimeSwitcherStatusDto *)frameData)->bacOutStatusList.append(bacOutStatus); + } + + ((TimeSwitcherStatusDto *)frameData)->frameType = TIME_SWITCHER_STATUS_FRAME_TYPE; + break; + + } + + return true; +} + +QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData) +{ + QList resultList; + if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true) + { + QByteArray ba; + for (int i = 0; i < rawData.size() - 1; i++) + { + if (rawData.at(i) != '\r') + { + ba.append(rawData.at(i)); + } else + { + if (rawData.at(i + 1) == '\n') + { + ba.append("\r\n"); + resultList.append(ba); + ba.clear(); + i++; + } else + { + ba.append(rawData.at(i)); + } + } + } + } + + return resultList; +} + +int TimeSwitcherProtocolBM::checkFrame(QByteArray rawData) +{ + // 帧尾不是\r\n + if (FRAME_TAIL.toLocal8Bit() != rawData.mid(rawData.size() - FRAME_TAIL.size())) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } + + // 帧头不是$GL + if (TIME_SWITCHER_INTERFACE_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_INTERFACE_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_INTERFACE_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::INTERFACE_FRAME; + } + } else if (TIME_SWITCHER_STATUS_FRAME_HEAD.toLocal8Bit() == rawData.mid(0, TIME_SWITCHER_STATUS_FRAME_HEAD.size())) + { + // 帧长度小于最小的长度 + if (rawData.size() < TIME_SWITCHER_STATUS_FRAME_MIN_LENGTH) + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } else + { + return TIME_SWITCHER_FRAME_TYPE::STATUS_FRAME; + } + } else + { + return TIME_SWITCHER_FRAME_TYPE::UNKNOW_FRAME; + } +} diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.h b/DeviceHub/protocol/TimeSwitcherProtocolBM.h new file mode 100644 index 0000000..910d8a7 --- /dev/null +++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.h @@ -0,0 +1,37 @@ +#ifndef TIMESWITCHERPROTOCOLBM_H +#define TIMESWITCHERPROTOCOLBM_H + +#include +#include + +#include "protocol/DeviceProtocolBase.h" +#include "protocol/dto/TimeSwitcherInterfaceDto.h" +#include "protocol/dto/TimeSwitcherStatusDto.h" + +class TimeSwitcherProtocolBM : public DeviceProtocolBase +{ + Q_OBJECT +public: + explicit TimeSwitcherProtocolBM(QObject *parent = nullptr); + ~TimeSwitcherProtocolBM(); + + // 解析数据 + bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); + DeviceFrameBaseDto * frameFactory(int frameType); + + // + QList extractFrameList(QByteArray rawData); + + // 检测帧格式,帧头帧尾 + int checkFrame(QByteArray rawData); + + enum TIME_SWITCHER_FRAME_TYPE + { + UNKNOW_FRAME = 0, + INTERFACE_FRAME = 1, + STATUS_FRAME = 2, + NETWORK_FRAME = 3 + }; +}; + +#endif // TIMESWITCHERPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..bc75c2d --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "FreqSwitcherInterfaceDto.h" + +FreqSwitcherInterfaceDto::FreqSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h new file mode 100644 index 0000000..5203af6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef FREQSWITCHERINTERFACEDTO_H +#define FREQSWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit FreqSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp new file mode 100644 index 0000000..dffbad6 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.cpp @@ -0,0 +1,51 @@ +#include "FreqSwitcherStatusDto.h" + +FreqSwitcherStatusDto::FreqSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject FreqSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("lockPhaseType", lockPhaseType); + dataObj.insert("digitalLockPhaseStatus", digitalLockPhaseStatus); + dataObj.insert("refFreqSrc", refFreqSrc); + dataObj.insert("freqAdjustAcc", freqAdjustAcc); + dataObj.insert("phaseAdjustAcc", phaseAdjustAcc); + + QJsonArray freqRefStatusArray; + QJsonArray localFreqDiffArray; + QJsonArray freqRefWeightArray; + QJsonArray inputFreqTypeArray; + QJsonArray outTenStatusArray; + QJsonArray outFiveStatusArray; + for (int i = 0; i < 5; i++) + { + freqRefStatusArray.append(freqRefStatusList.at(i)); + localFreqDiffArray.append(localFreqDiffList.at(i)); + freqRefWeightArray.append(freqRefWeightList.at(i)); + inputFreqTypeArray.append(inputFreqTypeList.at(i)); + } + for (int i = 0; i < 6; i++) + { + outTenStatusArray.append(outTenStatusList.at(i)); + outFiveStatusArray.append(outFiveStatusList.at(i)); + } + dataObj.insert("freqRefStatusArray", freqRefStatusArray); + dataObj.insert("localFreqDiffArray", localFreqDiffArray); + dataObj.insert("freqRefWeightArray", freqRefWeightArray); + dataObj.insert("inputFreqTypeArray", inputFreqTypeArray); + dataObj.insert("outTenStatusArray", outTenStatusArray); + dataObj.insert("outFiveStatusArray", outFiveStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h new file mode 100644 index 0000000..2cbdb12 --- /dev/null +++ b/DeviceHub/protocol/dto/FreqSwitcherStatusDto.h @@ -0,0 +1,31 @@ +#ifndef FREQSWITCHERSTATUSDTO_H +#define FREQSWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class FreqSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + FreqSwitcherStatusDto(QObject *parent = nullptr); + + QString lockPhaseType; // <1> + QString digitalLockPhaseStatus; // <2> + QString refSelectType; // <3> + QString refFreqSrc; // <4> + QList freqRefStatusList; // <5> + QList localFreqDiffList; // <6-10> + qlonglong freqAdjustAcc; // <11> 频率调整累计值,单位1pHz + qlonglong phaseAdjustAcc; // <12> 相位调整累计值,单位0.1fs + QList freqRefWeightList; // <13-17> + QString devStatus; // <18> + QList inputFreqTypeList; // <19> + QList outTenStatusList; // <20> + QList outFiveStatusList; // <21> + + QJsonObject toJSON(); +}; + +#endif // FREQSWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp deleted file mode 100644 index 33749fa..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "FrequencyTuningSettingDto.h" - -FrequencyTuningSettingDto::FrequencyTuningSettingDto(QObject *parent) : DeviceFrameBaseDto(parent) -{ - -} diff --git a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h b/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h deleted file mode 100644 index 17c9ba9..0000000 --- a/DeviceHub/protocol/dto/FrequencyTuningSettingDto.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FREQUENCYTUNINGSETTINGDTO_H -#define FREQUENCYTUNINGSETTINGDTO_H - -#include - -#include "DeviceFrameBaseDto.h" - -class FrequencyTuningSettingDto : public DeviceFrameBaseDto -{ - Q_OBJECT -public: - explicit FrequencyTuningSettingDto(QObject *parent = nullptr); - - qlonglong freqTunSet; - qlonglong phaseTunSet; - qlonglong phaseShiftSet; - qint8 singleSynchSet; - qlonglong secondWidthSet; -}; - -#endif // FREQUENCYTUNINGSETTINGDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp new file mode 100644 index 0000000..dfed520 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.cpp @@ -0,0 +1,21 @@ +#include "SignalGeneratorInterfaceDto.h" + +SignalGeneratorInterfaceDto::SignalGeneratorInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("keyControl", keyControl); + dataObj.insert("timeType", timeType); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h new file mode 100644 index 0000000..d4328cc --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorInterfaceDto.h @@ -0,0 +1,26 @@ +#ifndef SIGNALGENERATORINTERFACEDTO_H +#define SIGNALGENERATORINTERFACEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorInterfaceDto class + * 信号产生器 界面状态信息 + */ +class SignalGeneratorInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorInterfaceDto(QObject *parent = nullptr); + + QString keyControl; // <1>键盘控制情况:1=锁定;0=解锁 + QString timeType; // <2>时间显示类别:1=儒略日;0=年月日 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp new file mode 100644 index 0000000..84ce8fd --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.cpp @@ -0,0 +1,23 @@ +#include "SignalGeneratorMJDTimeDto.h" + +SignalGeneratorMJDTimeDto::SignalGeneratorMJDTimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorMJDTimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("mjdTime", mjdTime); + dataObj.insert("mjdDay", mjdDay); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h new file mode 100644 index 0000000..059acfe --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorMJDTimeDto.h @@ -0,0 +1,28 @@ +#ifndef SIGNALGENERATORMJDTIMEDTO_H +#define SIGNALGENERATORMJDTIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorMJDTimeDto class + * 信号产生器 MJD时间信息 + */ +class SignalGeneratorMJDTimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorMJDTimeDto(QObject *parent = nullptr); + + QString mjdTime; // <1> 时分秒 + QString mjdDay; // <2> 儒略日 + QString leapSec; // <3> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <4> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORMJDTIMEDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp new file mode 100644 index 0000000..736c4c7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.cpp @@ -0,0 +1,30 @@ +#include "SignalGeneratorStatusDto.h" + +SignalGeneratorStatusDto::SignalGeneratorStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("leap", leapSec); + dataObj.insert("leapTm", leapTimestamp); + dataObj.insert("freqStatus", freqSignalStatus); + dataObj.insert("freqType", freqSignalType); + dataObj.insert("oppsStatus", oppsSignalStatus); + dataObj.insert("phaseDiff", phaseDiff); + dataObj.insert("pulseWidth", pulseWidth); + dataObj.insert("phaseAcc", phaseShiftAcc); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h new file mode 100644 index 0000000..384cca3 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorStatusDto.h @@ -0,0 +1,35 @@ +#ifndef SIGNALGENERATORSTATUSDTO_H +#define SIGNALGENERATORSTATUSDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorStatusDto class + * 信号产生器 工作状态信息 + */ +class SignalGeneratorStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> 设备工作状态 + QString leapSec; // <2> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString leapTimestamp; // <3> 闰秒时刻,只精准至日 + QString freqSignalStatus; // <4> 频率信号状态:0:无效,1:有效; + QString freqSignalType; // <5> 频率信号类别:0:10MHz,1:5MHz; + QString oppsSignalStatus; // <6> 1PPS信号状态:0:无效,1:有效; + float phaseDiff; // <7> 输入1PPS与本地输出1PPS的相差,单位为1ns,带小数点后两位 + qlonglong pulseWidth; // <8> 1PPS脉宽,10000~500000000,单位为ns + qlonglong phaseShiftAcc; // <9> 1PPS移相量,单位1ps + qint8 bacRatio; // <10> B-AC调制比,2~6 + float bacRange; // <11> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORSTATUSDTO_H diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp new file mode 100644 index 0000000..8e5334c --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.cpp @@ -0,0 +1,25 @@ +#include "SignalGeneratorZDATimeDto.h" + +SignalGeneratorZDATimeDto::SignalGeneratorZDATimeDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject SignalGeneratorZDATimeDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("zdaTime", zdaTime); + dataObj.insert("zdaDay", zdaDay); + dataObj.insert("zdaMon", zdaMon); + dataObj.insert("zdaYear", zdaYear); + dataObj.insert("leapSec", leapSec); + dataObj.insert("valid", valid); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h new file mode 100644 index 0000000..79049a7 --- /dev/null +++ b/DeviceHub/protocol/dto/SignalGeneratorZDATimeDto.h @@ -0,0 +1,30 @@ +#ifndef SIGNALGENERATORZDATIMEDTO_H +#define SIGNALGENERATORZDATIMEDTO_H + +#include +#include "protocol/dto/DeviceFrameBaseDto.h" + +/** + * @brief The SignalGeneratorZDATimeDto class + * 信号产生器 ZDA时间信息 + */ +class SignalGeneratorZDATimeDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit SignalGeneratorZDATimeDto(QObject *parent = nullptr); + + QString zdaTime; // <1> 时分秒 + QString zdaDay; // <2> 日期 + QString zdaMon; // <3> 月 + QString zdaYear; // <4> 年 + QString leapSec; // <5> 闰秒标志:0=无闰秒;1=正闰秒;2=负闰秒 + QString valid; // <6> 有效标志:01=有效;00=无效 + + QJsonObject toJSON(); + +signals: + +}; + +#endif // SIGNALGENERATORZDATIMEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp new file mode 100644 index 0000000..b9b2894 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.cpp @@ -0,0 +1,20 @@ +#include "TimeSwitcherInterfaceDto.h" + +TimeSwitcherInterfaceDto::TimeSwitcherInterfaceDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherInterfaceDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("ctrlStatus", ctrlStatus); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h new file mode 100644 index 0000000..11e4b53 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherInterfaceDto.h @@ -0,0 +1,19 @@ +#ifndef TIMESWITCHERINTERFACEDTO_H +#define TIMESWITCHERINTERFACEDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class TimeSwitcherInterfaceDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeSwitcherInterfaceDto(QObject *parent = nullptr); + + QString ctrlStatus; // <1> + + QJsonObject toJSON(); +}; + +#endif // TIMESWITCHERINTERFACEDTO_H diff --git a/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp new file mode 100644 index 0000000..1cad164 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.cpp @@ -0,0 +1,65 @@ +#include "TimeSwitcherStatusDto.h" + +TimeSwitcherStatusDto::TimeSwitcherStatusDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeSwitcherStatusDto::toJSON() +{ + QJsonObject jsonObj; + + QJsonObject dataObj; + dataObj.insert("devStatus", devStatus); + dataObj.insert("refSelectType", refSelectType); + dataObj.insert("refTmSrc", refTmSrc); + dataObj.insert("oppsPhaseAccOut", oppsPhaseAccOut); + dataObj.insert("bacRatio", bacRatio); + dataObj.insert("bacRange", bacRange); + + QJsonArray tmSrcStatusArray; + QJsonArray tmSrcStatusStrArray; + QJsonArray localTmDiffArray; + QJsonArray delayCompensArray; + QJsonArray oppsOutStatusArray; + QJsonArray bdcOutStatusArray; + QJsonArray bacOutStatusArray; + for (int i = 0; i < 5; i++) + { + tmSrcStatusArray.append(tmSrcStatusList.at(i)); + QString tmSrcStatus = tmSrcStatusList.at(i); + if (tmSrcStatus.length() == 3) + { + QString tmSrcStatusStr = ""; + for (int j = 0; j < 3; j++) + { + if (tmSrcStatus.mid(j, 1) == '1') + { + tmSrcStatusStr += tmSrcStr[j] + ","; + } + } + tmSrcStatusStrArray.append(tmSrcStatusStr.mid(0, tmSrcStatusStr.length() - 1)); + } else + { + tmSrcStatusStrArray.append(""); + } + localTmDiffArray.append(localTmDiffList.at(i)); + delayCompensArray.append(delayCompensList.at(i)); + oppsOutStatusArray.append(oppsOutStatusList.at(i)); + bdcOutStatusArray.append(bdcOutStatusList.at(i)); + bacOutStatusArray.append(bacOutStatusList.at(i)); + } + dataObj.insert("tmSrcStatusArray", tmSrcStatusArray); + dataObj.insert("tmSrcStatusStrArray", tmSrcStatusStrArray); + dataObj.insert("localTmDiffArray", localTmDiffArray); + dataObj.insert("delayCompensArray", delayCompensArray); + dataObj.insert("oppsOutStatusArray", oppsOutStatusArray); + dataObj.insert("bdcOutStatusArray", bdcOutStatusArray); + dataObj.insert("bacOutStatusArray", bacOutStatusArray); + + jsonObj.insert("ts", this->milisecond); + jsonObj.insert("frameType", this->frameType); + jsonObj.insert("data", dataObj); + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeSwitcherStatusDto.h b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.h new file mode 100644 index 0000000..3862cc4 --- /dev/null +++ b/DeviceHub/protocol/dto/TimeSwitcherStatusDto.h @@ -0,0 +1,33 @@ +#ifndef TIMESWITCHERSTATUSDTO_H +#define TIMESWITCHERSTATUSDTO_H + +#include + +#include "protocol/dto/DeviceFrameBaseDto.h" + +class TimeSwitcherStatusDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeSwitcherStatusDto(QObject *parent = nullptr); + + QString devStatus; // <1> + QString refSelectType; // <2> + QString refTmSrc; // <3> + QList tmSrcStatusList; // <4-8> + QList localTmDiffList; // <9-13> + qlonglong oppsPhaseAccOut; // <14> + qint8 bacRatio; // <15> B-AC调制比,2~6 + float bacRange; // <16> B-AC幅度,5表示0.5V,50表示5.0V,100表示10V + QList delayCompensList; // <17-22> + QList oppsOutStatusList; // <23> + QList bdcOutStatusList; // <24> + QList bacOutStatusList; // <25> + + QJsonObject toJSON(); + +private: + const QString tmSrcStr[3] = {"1PPS", "B-DC", "B-AC"}; +}; + +#endif // TIMESWITCHERSTATUSDTO_H diff --git a/DeviceHub/protocol/protocol.pri b/DeviceHub/protocol/protocol.pri index 01d3e1a..791654b 100644 --- a/DeviceHub/protocol/protocol.pri +++ b/DeviceHub/protocol/protocol.pri @@ -2,51 +2,48 @@ HEADERS += $$PWD/dto/DeviceFrameBaseDto.h HEADERS += $$PWD/dto/FrequencyTuningStatusFreqDto.h HEADERS += $$PWD/dto/FrequencyTuningStatusPulseDto.h -HEADERS += $$PWD/dto/FrequencyTuningSettingDto.h +HEADERS += $$PWD/dto/SignalGeneratorStatusDto.h +HEADERS += $$PWD/dto/SignalGeneratorInterfaceDto.h +HEADERS += $$PWD/dto/SignalGeneratorZDATimeDto.h +HEADERS += $$PWD/dto/SignalGeneratorMJDTimeDto.h +HEADERS += $$PWD/dto/TimeSwitcherStatusDto.h +HEADERS += $$PWD/dto/TimeSwitcherInterfaceDto.h +HEADERS += $$PWD/dto/FreqSwitcherInterfaceDto.h +HEADERS += $$PWD/dto/FreqSwitcherStatusDto.h HEADERS += $$PWD/DeviceProtocolBase.h HEADERS += $$PWD/FrequencyTuningProtocolBM.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/SignalGeneratorProtocolBM.h +HEADERS += $$PWD/TimeSwitcherProtocolBM.h +HEADERS += $$PWD/FreqSwitcherProtocolBM.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/SignalGeneratorProtocolBM.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/SignalGeneratorStatusDto.cpp +SOURCES += $$PWD/dto/SignalGeneratorInterfaceDto.cpp +SOURCES += $$PWD/dto/SignalGeneratorZDATimeDto.cpp +SOURCES += $$PWD/dto/SignalGeneratorMJDTimeDto.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/TimeSwitcherStatusDto.cpp +SOURCES += $$PWD/dto/TimeSwitcherInterfaceDto.cpp +SOURCES += $$PWD/dto/FreqSwitcherInterfaceDto.cpp #SOURCES += $$PWD/dto/TimeReplicatorStatusDto.cpp -#SOURCES += $$PWD/dto/FreqSwitcherStatusDto.cpp +SOURCES += $$PWD/dto/FreqSwitcherStatusDto.cpp SOURCES += $$PWD/DeviceProtocolBase.cpp SOURCES += $$PWD/FrequencyTuningProtocolBM.cpp +SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp #SOURCES += $$PWD/dto/FreqReplicatorStatusDto.cpp #SOURCES += $$PWD/dto/BCodeTerminalStatusDto.cpp -#SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp -#SOURCES += $$PWD/TimeSwitcherProtocolBM.cpp -#SOURCES += $$PWD/FreqSwitcherProtocolBM.cpp +SOURCES += $$PWD/TimeSwitcherProtocolBM.cpp +SOURCES += $$PWD/FreqSwitcherProtocolBM.cpp #SOURCES += $$PWD/TimeReplicatorProtocolBM.cpp #SOURCES += $$PWD/FreqReplicatorProtocolTX.cpp #SOURCES += $$PWD/BCodeTerminalProtocolBM.cpp