diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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 c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp index dbd6914..4200297 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp @@ -12,57 +12,94 @@ bool TimeReplicatorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType) { - if (frameType != 1) - return false; - - qint8 length = rawData.mid(1, 2).toInt(0, 16); - QByteArray content = rawData.mid(19, length - 24); - qint8 count; - int inputByte = 0; - QString outStr = ""; - - ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); - if (length < 0x30) + if (frameType == TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) { - count = 2; - inputByte = content.mid(2, 1).toInt(); - outStr = content.mid(3, 8 * count); - } else - { - count = 4; - inputByte = content.mid(2, 2).toInt(); - outStr = content.mid(4, 8 * count); - } + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(19, length - 24); + qint8 count; + int inputByte = 0; + QString outStr = ""; - ((TimeReplicatorStatusDto *) frameData)->inCount = count; - for (int i = 0; i < count; i++) - { - qint8 in = inputByte % 2; - ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); - inputByte = inputByte / 2; - - QString output = ""; - for (int j = 0; j < 8; j++) + ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); + if (length < 0x30) { - output += outStr.at(i * 8 + j); - output += ","; + count = 2; + inputByte = content.mid(2, 1).toInt(); + outStr = content.mid(3, 8 * count); + } else + { + count = 4; + inputByte = content.mid(2, 2).toInt(); + outStr = content.mid(4, 8 * count); } - ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + + ((TimeReplicatorStatusDto *) frameData)->inCount = count; + for (int i = 0; i < count; i++) + { + qint8 in = inputByte % 2; + ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); + inputByte = inputByte / 2; + + QString output = ""; + for (int j = 0; j < 8; j++) + { + output += outStr.at(i * 8 + j); + output += ","; + } + ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + } + + ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; + + return true; + } else if (frameType == TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(length - 6, 1); + + ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0; + + return true; } - - ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; - - return true; } -QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; + commandBytes.append("3"); commandBytes.append("1308-13").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); - commandBytes.append(valueSet.replace(",", "")); + + if (commandType == "1") + { + // 4*8 or 2*8 + QStringList valueList = valueSet.split(","); + for (int i = 0; i < valueList.size(); i++) + { + QString value = valueList.at(i); + while (value.size() < 6) + { + value.prepend("0"); + } + commandBytes.append(value); + } + } else if (commandType == "2") + { + QStringList delayParams = valueSet.split(","); + if (delayParams.size() == 2) + { + commandBytes.append(delayParams.at(0)); + QString delay = delayParams.at(1); + while(delay.size() < 11) + { + delay.insert(1, "0"); + } + commandBytes.append(delay); + } + } + commandBytes.append(this->buildCRC16(commandBytes)); commandBytes.append("*"); @@ -75,15 +112,36 @@ int TimeReplicatorProtocolBM::checkFrame(QByteArray rawData) { if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' && - rawData.at(3) == '2' && rawData.at(20) == '2' && rawData.size() == rawData.mid(1, 2).toInt(0, 16)) - return 1; - return 0; + { + if (rawData.at(3) == '2' && rawData.at(20) == '2') + { + return TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME; + } else if (rawData.at(3) == '4') + { + return TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME; + } + } else { + return TIME_REPLICATOR_FRAME_TYPE::UNKNOW_FRAME; + } } DeviceFrameBaseDto * TimeReplicatorProtocolBM::frameFactory(int frameType) { - DeviceFrameBaseDto * frameData = new TimeReplicatorStatusDto(); + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeReplicatorStatusDto(); + break; + + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME : + frameData = new TimeReplicatorCmdRepDto(); + break; + + default: + frameData = nullptr; + break; + } return frameData; } @@ -91,7 +149,8 @@ QList TimeReplicatorProtocolBM::extractFrameList(QByteArray rawData) { QList resultList; - while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true) + while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) && + rawData.startsWith("$") == true) { QByteArray ba; qint8 length = rawData.mid(1, 2).toInt(0, 16); diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp index dbd6914..4200297 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp @@ -12,57 +12,94 @@ bool TimeReplicatorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType) { - if (frameType != 1) - return false; - - qint8 length = rawData.mid(1, 2).toInt(0, 16); - QByteArray content = rawData.mid(19, length - 24); - qint8 count; - int inputByte = 0; - QString outStr = ""; - - ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); - if (length < 0x30) + if (frameType == TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) { - count = 2; - inputByte = content.mid(2, 1).toInt(); - outStr = content.mid(3, 8 * count); - } else - { - count = 4; - inputByte = content.mid(2, 2).toInt(); - outStr = content.mid(4, 8 * count); - } + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(19, length - 24); + qint8 count; + int inputByte = 0; + QString outStr = ""; - ((TimeReplicatorStatusDto *) frameData)->inCount = count; - for (int i = 0; i < count; i++) - { - qint8 in = inputByte % 2; - ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); - inputByte = inputByte / 2; - - QString output = ""; - for (int j = 0; j < 8; j++) + ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); + if (length < 0x30) { - output += outStr.at(i * 8 + j); - output += ","; + count = 2; + inputByte = content.mid(2, 1).toInt(); + outStr = content.mid(3, 8 * count); + } else + { + count = 4; + inputByte = content.mid(2, 2).toInt(); + outStr = content.mid(4, 8 * count); } - ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + + ((TimeReplicatorStatusDto *) frameData)->inCount = count; + for (int i = 0; i < count; i++) + { + qint8 in = inputByte % 2; + ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); + inputByte = inputByte / 2; + + QString output = ""; + for (int j = 0; j < 8; j++) + { + output += outStr.at(i * 8 + j); + output += ","; + } + ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + } + + ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; + + return true; + } else if (frameType == TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(length - 6, 1); + + ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0; + + return true; } - - ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; - - return true; } -QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; + commandBytes.append("3"); commandBytes.append("1308-13").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); - commandBytes.append(valueSet.replace(",", "")); + + if (commandType == "1") + { + // 4*8 or 2*8 + QStringList valueList = valueSet.split(","); + for (int i = 0; i < valueList.size(); i++) + { + QString value = valueList.at(i); + while (value.size() < 6) + { + value.prepend("0"); + } + commandBytes.append(value); + } + } else if (commandType == "2") + { + QStringList delayParams = valueSet.split(","); + if (delayParams.size() == 2) + { + commandBytes.append(delayParams.at(0)); + QString delay = delayParams.at(1); + while(delay.size() < 11) + { + delay.insert(1, "0"); + } + commandBytes.append(delay); + } + } + commandBytes.append(this->buildCRC16(commandBytes)); commandBytes.append("*"); @@ -75,15 +112,36 @@ int TimeReplicatorProtocolBM::checkFrame(QByteArray rawData) { if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' && - rawData.at(3) == '2' && rawData.at(20) == '2' && rawData.size() == rawData.mid(1, 2).toInt(0, 16)) - return 1; - return 0; + { + if (rawData.at(3) == '2' && rawData.at(20) == '2') + { + return TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME; + } else if (rawData.at(3) == '4') + { + return TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME; + } + } else { + return TIME_REPLICATOR_FRAME_TYPE::UNKNOW_FRAME; + } } DeviceFrameBaseDto * TimeReplicatorProtocolBM::frameFactory(int frameType) { - DeviceFrameBaseDto * frameData = new TimeReplicatorStatusDto(); + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeReplicatorStatusDto(); + break; + + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME : + frameData = new TimeReplicatorCmdRepDto(); + break; + + default: + frameData = nullptr; + break; + } return frameData; } @@ -91,7 +149,8 @@ QList TimeReplicatorProtocolBM::extractFrameList(QByteArray rawData) { QList resultList; - while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true) + while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) && + rawData.startsWith("$") == true) { QByteArray ba; qint8 length = rawData.mid(1, 2).toInt(0, 16); diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h index a310e61..405cd74 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h @@ -6,6 +6,7 @@ #include "common/utils/QByteUtil.h" #include "DeviceProtocolBase.h" #include "dto/TimeReplicatorStatusDto.h" +#include "dto/TimeReplicatorCmdRepDto.h" class TimeReplicatorProtocolBM : public DeviceProtocolBase { @@ -16,7 +17,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // @@ -24,6 +25,13 @@ // 检测帧格式,帧头帧尾 int checkFrame(QByteArray rawData); + + enum TIME_REPLICATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + STATUS_FRAME = 1, + CMDREP_FRAME = 2 + }; }; #endif // TIMEREPLICATORPROTOCOLBM_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp index dbd6914..4200297 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp @@ -12,57 +12,94 @@ bool TimeReplicatorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType) { - if (frameType != 1) - return false; - - qint8 length = rawData.mid(1, 2).toInt(0, 16); - QByteArray content = rawData.mid(19, length - 24); - qint8 count; - int inputByte = 0; - QString outStr = ""; - - ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); - if (length < 0x30) + if (frameType == TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) { - count = 2; - inputByte = content.mid(2, 1).toInt(); - outStr = content.mid(3, 8 * count); - } else - { - count = 4; - inputByte = content.mid(2, 2).toInt(); - outStr = content.mid(4, 8 * count); - } + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(19, length - 24); + qint8 count; + int inputByte = 0; + QString outStr = ""; - ((TimeReplicatorStatusDto *) frameData)->inCount = count; - for (int i = 0; i < count; i++) - { - qint8 in = inputByte % 2; - ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); - inputByte = inputByte / 2; - - QString output = ""; - for (int j = 0; j < 8; j++) + ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); + if (length < 0x30) { - output += outStr.at(i * 8 + j); - output += ","; + count = 2; + inputByte = content.mid(2, 1).toInt(); + outStr = content.mid(3, 8 * count); + } else + { + count = 4; + inputByte = content.mid(2, 2).toInt(); + outStr = content.mid(4, 8 * count); } - ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + + ((TimeReplicatorStatusDto *) frameData)->inCount = count; + for (int i = 0; i < count; i++) + { + qint8 in = inputByte % 2; + ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); + inputByte = inputByte / 2; + + QString output = ""; + for (int j = 0; j < 8; j++) + { + output += outStr.at(i * 8 + j); + output += ","; + } + ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + } + + ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; + + return true; + } else if (frameType == TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(length - 6, 1); + + ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0; + + return true; } - - ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; - - return true; } -QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; + commandBytes.append("3"); commandBytes.append("1308-13").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); - commandBytes.append(valueSet.replace(",", "")); + + if (commandType == "1") + { + // 4*8 or 2*8 + QStringList valueList = valueSet.split(","); + for (int i = 0; i < valueList.size(); i++) + { + QString value = valueList.at(i); + while (value.size() < 6) + { + value.prepend("0"); + } + commandBytes.append(value); + } + } else if (commandType == "2") + { + QStringList delayParams = valueSet.split(","); + if (delayParams.size() == 2) + { + commandBytes.append(delayParams.at(0)); + QString delay = delayParams.at(1); + while(delay.size() < 11) + { + delay.insert(1, "0"); + } + commandBytes.append(delay); + } + } + commandBytes.append(this->buildCRC16(commandBytes)); commandBytes.append("*"); @@ -75,15 +112,36 @@ int TimeReplicatorProtocolBM::checkFrame(QByteArray rawData) { if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' && - rawData.at(3) == '2' && rawData.at(20) == '2' && rawData.size() == rawData.mid(1, 2).toInt(0, 16)) - return 1; - return 0; + { + if (rawData.at(3) == '2' && rawData.at(20) == '2') + { + return TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME; + } else if (rawData.at(3) == '4') + { + return TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME; + } + } else { + return TIME_REPLICATOR_FRAME_TYPE::UNKNOW_FRAME; + } } DeviceFrameBaseDto * TimeReplicatorProtocolBM::frameFactory(int frameType) { - DeviceFrameBaseDto * frameData = new TimeReplicatorStatusDto(); + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeReplicatorStatusDto(); + break; + + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME : + frameData = new TimeReplicatorCmdRepDto(); + break; + + default: + frameData = nullptr; + break; + } return frameData; } @@ -91,7 +149,8 @@ QList TimeReplicatorProtocolBM::extractFrameList(QByteArray rawData) { QList resultList; - while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true) + while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) && + rawData.startsWith("$") == true) { QByteArray ba; qint8 length = rawData.mid(1, 2).toInt(0, 16); diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h index a310e61..405cd74 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h @@ -6,6 +6,7 @@ #include "common/utils/QByteUtil.h" #include "DeviceProtocolBase.h" #include "dto/TimeReplicatorStatusDto.h" +#include "dto/TimeReplicatorCmdRepDto.h" class TimeReplicatorProtocolBM : public DeviceProtocolBase { @@ -16,7 +17,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // @@ -24,6 +25,13 @@ // 检测帧格式,帧头帧尾 int checkFrame(QByteArray rawData); + + enum TIME_REPLICATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + STATUS_FRAME = 1, + CMDREP_FRAME = 2 + }; }; #endif // TIMEREPLICATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h index f14808f..02457ce 100644 --- a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -19,6 +19,8 @@ QString devCode; QString frameType; // 帧类型 + QString commandId; + virtual QJsonObject toJSON() = 0; signals: diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp index dbd6914..4200297 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp @@ -12,57 +12,94 @@ bool TimeReplicatorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType) { - if (frameType != 1) - return false; - - qint8 length = rawData.mid(1, 2).toInt(0, 16); - QByteArray content = rawData.mid(19, length - 24); - qint8 count; - int inputByte = 0; - QString outStr = ""; - - ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); - if (length < 0x30) + if (frameType == TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) { - count = 2; - inputByte = content.mid(2, 1).toInt(); - outStr = content.mid(3, 8 * count); - } else - { - count = 4; - inputByte = content.mid(2, 2).toInt(); - outStr = content.mid(4, 8 * count); - } + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(19, length - 24); + qint8 count; + int inputByte = 0; + QString outStr = ""; - ((TimeReplicatorStatusDto *) frameData)->inCount = count; - for (int i = 0; i < count; i++) - { - qint8 in = inputByte % 2; - ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); - inputByte = inputByte / 2; - - QString output = ""; - for (int j = 0; j < 8; j++) + ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); + if (length < 0x30) { - output += outStr.at(i * 8 + j); - output += ","; + count = 2; + inputByte = content.mid(2, 1).toInt(); + outStr = content.mid(3, 8 * count); + } else + { + count = 4; + inputByte = content.mid(2, 2).toInt(); + outStr = content.mid(4, 8 * count); } - ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + + ((TimeReplicatorStatusDto *) frameData)->inCount = count; + for (int i = 0; i < count; i++) + { + qint8 in = inputByte % 2; + ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); + inputByte = inputByte / 2; + + QString output = ""; + for (int j = 0; j < 8; j++) + { + output += outStr.at(i * 8 + j); + output += ","; + } + ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + } + + ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; + + return true; + } else if (frameType == TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(length - 6, 1); + + ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0; + + return true; } - - ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; - - return true; } -QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; + commandBytes.append("3"); commandBytes.append("1308-13").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); - commandBytes.append(valueSet.replace(",", "")); + + if (commandType == "1") + { + // 4*8 or 2*8 + QStringList valueList = valueSet.split(","); + for (int i = 0; i < valueList.size(); i++) + { + QString value = valueList.at(i); + while (value.size() < 6) + { + value.prepend("0"); + } + commandBytes.append(value); + } + } else if (commandType == "2") + { + QStringList delayParams = valueSet.split(","); + if (delayParams.size() == 2) + { + commandBytes.append(delayParams.at(0)); + QString delay = delayParams.at(1); + while(delay.size() < 11) + { + delay.insert(1, "0"); + } + commandBytes.append(delay); + } + } + commandBytes.append(this->buildCRC16(commandBytes)); commandBytes.append("*"); @@ -75,15 +112,36 @@ int TimeReplicatorProtocolBM::checkFrame(QByteArray rawData) { if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' && - rawData.at(3) == '2' && rawData.at(20) == '2' && rawData.size() == rawData.mid(1, 2).toInt(0, 16)) - return 1; - return 0; + { + if (rawData.at(3) == '2' && rawData.at(20) == '2') + { + return TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME; + } else if (rawData.at(3) == '4') + { + return TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME; + } + } else { + return TIME_REPLICATOR_FRAME_TYPE::UNKNOW_FRAME; + } } DeviceFrameBaseDto * TimeReplicatorProtocolBM::frameFactory(int frameType) { - DeviceFrameBaseDto * frameData = new TimeReplicatorStatusDto(); + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeReplicatorStatusDto(); + break; + + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME : + frameData = new TimeReplicatorCmdRepDto(); + break; + + default: + frameData = nullptr; + break; + } return frameData; } @@ -91,7 +149,8 @@ QList TimeReplicatorProtocolBM::extractFrameList(QByteArray rawData) { QList resultList; - while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true) + while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) && + rawData.startsWith("$") == true) { QByteArray ba; qint8 length = rawData.mid(1, 2).toInt(0, 16); diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h index a310e61..405cd74 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h @@ -6,6 +6,7 @@ #include "common/utils/QByteUtil.h" #include "DeviceProtocolBase.h" #include "dto/TimeReplicatorStatusDto.h" +#include "dto/TimeReplicatorCmdRepDto.h" class TimeReplicatorProtocolBM : public DeviceProtocolBase { @@ -16,7 +17,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // @@ -24,6 +25,13 @@ // 检测帧格式,帧头帧尾 int checkFrame(QByteArray rawData); + + enum TIME_REPLICATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + STATUS_FRAME = 1, + CMDREP_FRAME = 2 + }; }; #endif // TIMEREPLICATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h index f14808f..02457ce 100644 --- a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -19,6 +19,8 @@ QString devCode; QString frameType; // 帧类型 + QString commandId; + virtual QJsonObject toJSON() = 0; signals: diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp new file mode 100644 index 0000000..cb6a8ed --- /dev/null +++ b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp @@ -0,0 +1,20 @@ +#include "TimeReplicatorCmdRepDto.h" + +TimeReplicatorCmdRepDto::TimeReplicatorCmdRepDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeReplicatorCmdRepDto::toJSON() +{ + QJsonObject jsonObj; + + jsonObj.insert("status", QString::number(this->cmdStatus)); + jsonObj.insert("commandId", this->commandId); + if (this->cmdStatus != 1) + { + jsonObj.insert("remarks", "failed"); + } + + return jsonObj; +} diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp index dbd6914..4200297 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp @@ -12,57 +12,94 @@ bool TimeReplicatorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType) { - if (frameType != 1) - return false; - - qint8 length = rawData.mid(1, 2).toInt(0, 16); - QByteArray content = rawData.mid(19, length - 24); - qint8 count; - int inputByte = 0; - QString outStr = ""; - - ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); - if (length < 0x30) + if (frameType == TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) { - count = 2; - inputByte = content.mid(2, 1).toInt(); - outStr = content.mid(3, 8 * count); - } else - { - count = 4; - inputByte = content.mid(2, 2).toInt(); - outStr = content.mid(4, 8 * count); - } + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(19, length - 24); + qint8 count; + int inputByte = 0; + QString outStr = ""; - ((TimeReplicatorStatusDto *) frameData)->inCount = count; - for (int i = 0; i < count; i++) - { - qint8 in = inputByte % 2; - ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); - inputByte = inputByte / 2; - - QString output = ""; - for (int j = 0; j < 8; j++) + ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); + if (length < 0x30) { - output += outStr.at(i * 8 + j); - output += ","; + count = 2; + inputByte = content.mid(2, 1).toInt(); + outStr = content.mid(3, 8 * count); + } else + { + count = 4; + inputByte = content.mid(2, 2).toInt(); + outStr = content.mid(4, 8 * count); } - ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + + ((TimeReplicatorStatusDto *) frameData)->inCount = count; + for (int i = 0; i < count; i++) + { + qint8 in = inputByte % 2; + ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); + inputByte = inputByte / 2; + + QString output = ""; + for (int j = 0; j < 8; j++) + { + output += outStr.at(i * 8 + j); + output += ","; + } + ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + } + + ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; + + return true; + } else if (frameType == TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(length - 6, 1); + + ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0; + + return true; } - - ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; - - return true; } -QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; + commandBytes.append("3"); commandBytes.append("1308-13").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); - commandBytes.append(valueSet.replace(",", "")); + + if (commandType == "1") + { + // 4*8 or 2*8 + QStringList valueList = valueSet.split(","); + for (int i = 0; i < valueList.size(); i++) + { + QString value = valueList.at(i); + while (value.size() < 6) + { + value.prepend("0"); + } + commandBytes.append(value); + } + } else if (commandType == "2") + { + QStringList delayParams = valueSet.split(","); + if (delayParams.size() == 2) + { + commandBytes.append(delayParams.at(0)); + QString delay = delayParams.at(1); + while(delay.size() < 11) + { + delay.insert(1, "0"); + } + commandBytes.append(delay); + } + } + commandBytes.append(this->buildCRC16(commandBytes)); commandBytes.append("*"); @@ -75,15 +112,36 @@ int TimeReplicatorProtocolBM::checkFrame(QByteArray rawData) { if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' && - rawData.at(3) == '2' && rawData.at(20) == '2' && rawData.size() == rawData.mid(1, 2).toInt(0, 16)) - return 1; - return 0; + { + if (rawData.at(3) == '2' && rawData.at(20) == '2') + { + return TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME; + } else if (rawData.at(3) == '4') + { + return TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME; + } + } else { + return TIME_REPLICATOR_FRAME_TYPE::UNKNOW_FRAME; + } } DeviceFrameBaseDto * TimeReplicatorProtocolBM::frameFactory(int frameType) { - DeviceFrameBaseDto * frameData = new TimeReplicatorStatusDto(); + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeReplicatorStatusDto(); + break; + + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME : + frameData = new TimeReplicatorCmdRepDto(); + break; + + default: + frameData = nullptr; + break; + } return frameData; } @@ -91,7 +149,8 @@ QList TimeReplicatorProtocolBM::extractFrameList(QByteArray rawData) { QList resultList; - while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true) + while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) && + rawData.startsWith("$") == true) { QByteArray ba; qint8 length = rawData.mid(1, 2).toInt(0, 16); diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h index a310e61..405cd74 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h @@ -6,6 +6,7 @@ #include "common/utils/QByteUtil.h" #include "DeviceProtocolBase.h" #include "dto/TimeReplicatorStatusDto.h" +#include "dto/TimeReplicatorCmdRepDto.h" class TimeReplicatorProtocolBM : public DeviceProtocolBase { @@ -16,7 +17,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // @@ -24,6 +25,13 @@ // 检测帧格式,帧头帧尾 int checkFrame(QByteArray rawData); + + enum TIME_REPLICATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + STATUS_FRAME = 1, + CMDREP_FRAME = 2 + }; }; #endif // TIMEREPLICATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h index f14808f..02457ce 100644 --- a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -19,6 +19,8 @@ QString devCode; QString frameType; // 帧类型 + QString commandId; + virtual QJsonObject toJSON() = 0; signals: diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp new file mode 100644 index 0000000..cb6a8ed --- /dev/null +++ b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp @@ -0,0 +1,20 @@ +#include "TimeReplicatorCmdRepDto.h" + +TimeReplicatorCmdRepDto::TimeReplicatorCmdRepDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeReplicatorCmdRepDto::toJSON() +{ + QJsonObject jsonObj; + + jsonObj.insert("status", QString::number(this->cmdStatus)); + jsonObj.insert("commandId", this->commandId); + if (this->cmdStatus != 1) + { + jsonObj.insert("remarks", "failed"); + } + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h new file mode 100644 index 0000000..c74f54d --- /dev/null +++ b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h @@ -0,0 +1,24 @@ +#ifndef TIMEREPLICATORCMDREPDTO_H +#define TIMEREPLICATORCMDREPDTO_H + +#include + +#include "DeviceFrameBaseDto.h" + +class TimeReplicatorCmdRepDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeReplicatorCmdRepDto(QObject *parent = nullptr); + + qint8 cmdStatus; + QString remarks; + + QJsonObject toJSON() override; + +signals: + +public slots: +}; + +#endif // TIMEREPLICATORCMDREPDTO_H diff --git a/DeviceHub/DeviceHub.pro b/DeviceHub/DeviceHub.pro index c0e5306..5d0706d 100644 --- a/DeviceHub/DeviceHub.pro +++ b/DeviceHub/DeviceHub.pro @@ -15,9 +15,7 @@ # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 -SOURCES += main.cpp \ - KeyTimeSynchForm.cpp \ - TimeReplicatorForm.cpp +SOURCES += main.cpp SOURCES += DeviceHubWindow.cpp SOURCES += FrequencyTuningForm.cpp SOURCES += SignalGeneratorForm.cpp @@ -25,26 +23,25 @@ SOURCES += FreqSwitcherForm.cpp SOURCES += BCodeTerminalForm.cpp SOURCES += FreqReplicatorForm.cpp +SOURCES += TimeReplicatorForm.cpp -HEADERS += DeviceHubWindow.h \ - KeyTimeSynchForm.h \ - TimeReplicatorForm.h +HEADERS += DeviceHubWindow.h HEADERS += FrequencyTuningForm.h HEADERS += SignalGeneratorForm.h HEADERS += TimeSwitcherForm.h HEADERS += FreqSwitcherForm.h HEADERS += BCodeTerminalForm.h HEADERS += FreqReplicatorForm.h +HEADERS += TimeReplicatorForm.h -FORMS += DeviceHubWindow.ui \ - KeyTimeSynchForm.ui \ - TimeReplicatorForm.ui +FORMS += DeviceHubWindow.ui FORMS += FrequencyTuningForm.ui FORMS += SignalGeneratorForm.ui FORMS += TimeSwitcherForm.ui FORMS += FreqSwitcherForm.ui FORMS += BCodeTerminalForm.ui FORMS += FreqReplicatorForm.ui +FORMS += TimeReplicatorForm.ui DISTFILES += conf/config.ini diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 65ba2f0..6f1df82 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -226,12 +226,6 @@ ui->stackedWidget->addWidget(bCodeTermForm); } - if (devType == "08") - { - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - } - if (devType == "09") { timeRepForm = new TimeReplicatorForm(this); diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index cb5875a..cdc100b 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -12,7 +12,6 @@ #include "TimeSwitcherForm.h" #include "FreqSwitcherForm.h" #include "BCodeTerminalForm.h" -#include "KeyTimeSynchForm.h" #include "TimeReplicatorForm.h" #include "FreqReplicatorForm.h" @@ -43,7 +42,6 @@ TimeSwitcherForm * tmSwitForm; FreqSwitcherForm * freqSwitForm; BCodeTerminalForm * bCodeTermForm; - KeyTimeSynchForm * keyTmSynchForm; TimeReplicatorForm * timeRepForm; FreqReplicatorForm * freqRepForm; diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp index 0a6c833..22a78fc 100644 --- a/DeviceHub/TimeReplicatorForm.cpp +++ b/DeviceHub/TimeReplicatorForm.cpp @@ -19,12 +19,36 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } +} + +void TimeReplicatorForm::on_tmRepCmdRepButt_clicked() +{ + // 获取设备对象 + int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; + TimeReplicator * device = (TimeReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("09").at(devIndex); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivCmdReply(); + } } void TimeReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) { + QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString(); + if (currentDevCode != frameData->devCode) + { + return; + } + // 当前显示的设备编号 if (frameData->frameType == "0901") { @@ -71,4 +95,3 @@ } } - diff --git a/DeviceHub/TimeReplicatorForm.h b/DeviceHub/TimeReplicatorForm.h index dc73d85..955ef83 100644 --- a/DeviceHub/TimeReplicatorForm.h +++ b/DeviceHub/TimeReplicatorForm.h @@ -23,6 +23,8 @@ private slots: void on_tmRepButt_clicked(); + void on_tmRepCmdRepButt_clicked(); + private: Ui::TimeReplicatorForm *ui; }; diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui index 68d2ce4..d65fb8f 100644 --- a/DeviceHub/TimeReplicatorForm.ui +++ b/DeviceHub/TimeReplicatorForm.ui @@ -180,6 +180,19 @@ + + + + 260 + 20 + 180 + 40 + + + + MockTR CmdReply + + diff --git a/DeviceHub/common/utils/QKafkaProducer.cpp b/DeviceHub/common/utils/QKafkaProducer.cpp index 109e581..e6d3521 100644 --- a/DeviceHub/common/utils/QKafkaProducer.cpp +++ b/DeviceHub/common/utils/QKafkaProducer.cpp @@ -49,20 +49,7 @@ int QKafkaProducer::produceMessage(QString message) { - auto retCode = producer->produce(this->topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, - const_cast(message.toStdString().c_str()), message.size(), - nullptr, 0, 0, nullptr, nullptr); - - if (retCode != RdKafka::ERR_NO_ERROR) - { - std::cerr << "Failed to produce to topic " << topic.toStdString() << ": " << - RdKafka::err2str(retCode) << std::endl; - } else - { - std::cerr << "Enqueued message (" << message.size() << " bytes) " << - "for topic " << topic.toStdString() << "[" << message.toStdString() <<"]" << std::endl; - } - + auto retCode = this->produceMessage(this->topic, message); return retCode; } diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5d8ec7f..5329676 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -155,7 +155,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index d823431..7c32c09 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -13,10 +13,12 @@ explicit BCodeTerminal(QObject *parent = nullptr); ~BCodeTerminal(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; void afterFrameParse(DeviceFrameBaseDto * frameDto); - void sendDataToSerial(QByteArray data) override; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 77955aa..666615a 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -30,8 +30,10 @@ bool isSerialOpen(); virtual void sendDataToSerial(QByteArray data); virtual void afterFrameParse(DeviceFrameBaseDto * frameDto) = 0; + virtual void afterCommandReply(DeviceFrameBaseDto * frameDto) = 0; virtual void mockReceivData() = 0; + virtual void mockReceivCmdReply() = 0; DeviceProtocolBase * protocol; @@ -42,6 +44,8 @@ int baudRate; QString devType; + QString commandId; + QSerialPortUtil serialUtil; QSerialPortUtil serialUtilB; // serial port 2 QKafkaProducer kafkaProducer; diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 716f800..5353c0b 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -13,10 +13,14 @@ explicit FreqReplicator(QObject *parent = nullptr); ~FreqReplicator(); - void mockReceivData(); - void frameParse(QList frameList); + + void mockReceivData(); + void mockReceivCmdReply() {}; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data) {}; signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp index 5587395..0fd0785 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 9c17824..f073f4d 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -14,10 +14,12 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply() {}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 0a19747..640dc6a 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -158,7 +158,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index f8d2b91..5ede354 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,10 +14,12 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 0d2d909..223819d 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -161,7 +161,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 2c6ffb8..9a49fdd 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,10 +16,12 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index 0a96722..2e22c67 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -2,6 +2,7 @@ #include "DeviceHubWindow.h" #include #include +#include TimeReplicator::TimeReplicator(QObject *parent) : DeviceBase(parent) { @@ -35,12 +36,28 @@ QByteArray buffer; // time replicator - buffer.append("$2B21308-13 21010012200000000000000000faf0*"); - buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); - buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*"); -// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*"); - buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*"); + buffer.append("$2B21308-13 21010011230000000000000000faf0*").append("\r\n"); + this->dataReceivedHandler(buffer); + QTimer::singleShot(1000, this, [=](){ + QByteArray buffer; + buffer.clear(); + buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); + this->dataReceivedHandler(buffer); + }); + +// buffer.append("$3C21308-13 2101008220322222222111111110000000000000000ca24*"); +// buffer.append("$3C21308-13 21010052207111111111111111111111111000000005984*").append("\r\n"); +// buffer.append("$3C21308-13 2101005121511111111111111111111111111111111bcfe*").append("\r\n"); +// buffer.append("$3E21308-13 2101001211308-13 2101001210929H.1.00S.1.00000292b*").append("\r\n"); +} + +void TimeReplicator::mockReceivCmdReply() +{ + QByteArray buffer; + + // time replicator + buffer.append("$1941308-13 21010011eb4a*").append("\r\n"); this->dataReceivedHandler(buffer); } @@ -54,6 +71,7 @@ if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -75,7 +93,16 @@ frameDto->devCode = devCode; - this->afterFrameParse(frameDto); + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } } // 在此处释放内存,不影响后续显示 @@ -118,6 +145,29 @@ emit this->sendDataToDraw(frameDto); } +void TimeReplicator::afterCommandReply(DeviceFrameBaseDto * frameDto) +{ + // 0. 输出到日志文件中 + QString date = frameDto->timestamp.mid(0, 10); + + // 1. 原始字节数组数据 + QString filename = "raw_" + devCode + ".log"; + QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size()); + QLogUtil::writeRawDataLogByDate(date, filename, content); + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = frameDto->timestamp + " [recv] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + QJsonObject jsonObj = frameDto->toJSON(); + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); + } +} + void TimeReplicator::sendDataToSerial(QByteArray data) { data.append(FRAME_TAIL); @@ -158,16 +208,17 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - + this->commandId = command.value("commandId").toString(); +/* 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/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index f871c64..d903490 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -4,7 +4,9 @@ #include #include "device/DeviceBase.h" +#include "protocol/TimeReplicatorProtocolBM.h" #include "protocol/dto/TimeReplicatorStatusDto.h" +#include "protocol/dto/TimeReplicatorCmdRepDto.h" class TimeReplicator : public DeviceBase { @@ -14,8 +16,10 @@ ~TimeReplicator(); void mockReceivData(); + void mockReceivCmdReply(); void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto); void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index b53b501..fcaeb61 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -159,7 +159,7 @@ 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()); + QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index e091d94..a48cd9d 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -14,10 +14,12 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); - void mockReceivData() override; + void mockReceivData(); + void mockReceivCmdReply(){}; - void afterFrameParse(DeviceFrameBaseDto * frameDto) override; - void sendDataToSerial(QByteArray data) override; + void afterFrameParse(DeviceFrameBaseDto * frameDto); + void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp index 1dfe733..a88d372 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp @@ -48,13 +48,13 @@ return true; } -QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append("3"); commandBytes.append("1304-20").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); commandBytes.append(valueSet.replace(",", "")); commandBytes.append(this->buildCRC16(commandBytes)); diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h index dcd5212..accebdd 100644 --- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h +++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h @@ -16,7 +16,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // diff --git a/DeviceHub/protocol/DeviceProtocolBase.cpp b/DeviceHub/protocol/DeviceProtocolBase.cpp index 4109e8d..f5195d4 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.cpp +++ b/DeviceHub/protocol/DeviceProtocolBase.cpp @@ -39,33 +39,10 @@ return new FreqReplicatorProtocolTX(); } -// if (deviceType.contains("SignalGenerator") == true) -// { -// return new SignalGeneratorProtocolBM(); -// } else if (deviceType.contains("FrequencyTuning") == true) -// { -// return new FrequencyTuningProtocolBM(); -// } else if (deviceType.contains("TimeSwitcher") == true) -// { -// return new TimeSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqSwitcher") == true) -// { -// return new FreqSwitcherProtocolBM(); -// } else if (deviceType.contains("FreqReplicator") == true) -// { -// return new FreqReplicatorProtocolTX(); -// } else if (deviceType.contains("TimeReplicator") == true) -// { -// return new TimeReplicatorProtocolBM(); -// } else if (deviceType.contains("BCodeTerminal") == true) -// { -// return new BCodeTerminalProtocolBM(); -// } - return nullptr; } -QByteArray DeviceProtocolBase::generateSettingCommand(QString commandType, QString valueSet) +QByteArray DeviceProtocolBase::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; commandBytes.append(commandType).append(","); diff --git a/DeviceHub/protocol/DeviceProtocolBase.h b/DeviceHub/protocol/DeviceProtocolBase.h index 0b65687..64955ad 100644 --- a/DeviceHub/protocol/DeviceProtocolBase.h +++ b/DeviceHub/protocol/DeviceProtocolBase.h @@ -97,6 +97,8 @@ static const QString B_CODE_TERMINAL_STATUS_FRAME_TYPE = "0701"; static const QString TIME_REPLICATOR_STATUS_FRAME_TYPE = "0901"; +static const QString TIME_REPLICATOR_PHASE_CMDREP_TYPE = "0911"; +static const QString TIME_REPLICATOR_DELAY_CMDREP_TYPE = "0912"; static const QString FREQ_REPLICATOR_STATUS_AB_FRAME_TYPE = "1001"; static const QString FREQ_REPLICATOR_STATUS_CD_FRAME_TYPE = "1002"; @@ -117,7 +119,7 @@ virtual int checkFrame(QByteArray rawData) = 0; virtual QList extractFrameList(QByteArray rawData) = 0; virtual bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType) = 0; - virtual QByteArray generateSettingCommand(QString commandType, QString valueSet); + virtual QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); signals: diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp index dbd6914..4200297 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp @@ -12,57 +12,94 @@ bool TimeReplicatorProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto *frameData, int frameType) { - if (frameType != 1) - return false; - - qint8 length = rawData.mid(1, 2).toInt(0, 16); - QByteArray content = rawData.mid(19, length - 24); - qint8 count; - int inputByte = 0; - QString outStr = ""; - - ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); - if (length < 0x30) + if (frameType == TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) { - count = 2; - inputByte = content.mid(2, 1).toInt(); - outStr = content.mid(3, 8 * count); - } else - { - count = 4; - inputByte = content.mid(2, 2).toInt(); - outStr = content.mid(4, 8 * count); - } + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(19, length - 24); + qint8 count; + int inputByte = 0; + QString outStr = ""; - ((TimeReplicatorStatusDto *) frameData)->inCount = count; - for (int i = 0; i < count; i++) - { - qint8 in = inputByte % 2; - ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); - inputByte = inputByte / 2; - - QString output = ""; - for (int j = 0; j < 8; j++) + ((TimeReplicatorStatusDto *) frameData)->devStatus = content.at(0); + if (length < 0x30) { - output += outStr.at(i * 8 + j); - output += ","; + count = 2; + inputByte = content.mid(2, 1).toInt(); + outStr = content.mid(3, 8 * count); + } else + { + count = 4; + inputByte = content.mid(2, 2).toInt(); + outStr = content.mid(4, 8 * count); } - ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + + ((TimeReplicatorStatusDto *) frameData)->inCount = count; + for (int i = 0; i < count; i++) + { + qint8 in = inputByte % 2; + ((TimeReplicatorStatusDto *) frameData)->inValid.append(in == 1 ? "1" : "0"); + inputByte = inputByte / 2; + + QString output = ""; + for (int j = 0; j < 8; j++) + { + output += outStr.at(i * 8 + j); + output += ","; + } + ((TimeReplicatorStatusDto *) frameData)->outValid.append(output.mid(0, output.size() - 1)); + } + + ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; + + return true; + } else if (frameType == TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + qint8 length = rawData.mid(1, 2).toInt(0, 16); + QByteArray content = rawData.mid(length - 6, 1); + + ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0; + + return true; } - - ((TimeReplicatorStatusDto *)frameData)->frameType = TIME_REPLICATOR_STATUS_FRAME_TYPE; - - return true; } -QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString commandType, QString valueSet) +QByteArray TimeReplicatorProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet) { QByteArray commandBytes; + commandBytes.append("3"); commandBytes.append("1308-13").append(0x20); - commandBytes.append("2101001"); + commandBytes.append(devCode); commandBytes.append(commandType); - commandBytes.append(valueSet.replace(",", "")); + + if (commandType == "1") + { + // 4*8 or 2*8 + QStringList valueList = valueSet.split(","); + for (int i = 0; i < valueList.size(); i++) + { + QString value = valueList.at(i); + while (value.size() < 6) + { + value.prepend("0"); + } + commandBytes.append(value); + } + } else if (commandType == "2") + { + QStringList delayParams = valueSet.split(","); + if (delayParams.size() == 2) + { + commandBytes.append(delayParams.at(0)); + QString delay = delayParams.at(1); + while(delay.size() < 11) + { + delay.insert(1, "0"); + } + commandBytes.append(delay); + } + } + commandBytes.append(this->buildCRC16(commandBytes)); commandBytes.append("*"); @@ -75,15 +112,36 @@ int TimeReplicatorProtocolBM::checkFrame(QByteArray rawData) { if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' && - rawData.at(3) == '2' && rawData.at(20) == '2' && rawData.size() == rawData.mid(1, 2).toInt(0, 16)) - return 1; - return 0; + { + if (rawData.at(3) == '2' && rawData.at(20) == '2') + { + return TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME; + } else if (rawData.at(3) == '4') + { + return TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME; + } + } else { + return TIME_REPLICATOR_FRAME_TYPE::UNKNOW_FRAME; + } } DeviceFrameBaseDto * TimeReplicatorProtocolBM::frameFactory(int frameType) { - DeviceFrameBaseDto * frameData = new TimeReplicatorStatusDto(); + DeviceFrameBaseDto * frameData = 0; + switch (frameType) { + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME : + frameData = new TimeReplicatorStatusDto(); + break; + + case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME : + frameData = new TimeReplicatorCmdRepDto(); + break; + + default: + frameData = nullptr; + break; + } return frameData; } @@ -91,7 +149,8 @@ QList TimeReplicatorProtocolBM::extractFrameList(QByteArray rawData) { QList resultList; - while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true) + while ((rawData.endsWith(QByteArray("*")) == true || rawData.endsWith(QByteArray("*\r\n")) == true) && + rawData.startsWith("$") == true) { QByteArray ba; qint8 length = rawData.mid(1, 2).toInt(0, 16); diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h index a310e61..405cd74 100644 --- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h +++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h @@ -6,6 +6,7 @@ #include "common/utils/QByteUtil.h" #include "DeviceProtocolBase.h" #include "dto/TimeReplicatorStatusDto.h" +#include "dto/TimeReplicatorCmdRepDto.h" class TimeReplicatorProtocolBM : public DeviceProtocolBase { @@ -16,7 +17,7 @@ // 解析数据 bool parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType); - QByteArray generateSettingCommand(QString commandType, QString valueSet); + QByteArray generateSettingCommand(QString devCode, QString commandType, QString valueSet); DeviceFrameBaseDto * frameFactory(int frameType); // @@ -24,6 +25,13 @@ // 检测帧格式,帧头帧尾 int checkFrame(QByteArray rawData); + + enum TIME_REPLICATOR_FRAME_TYPE + { + UNKNOW_FRAME = 0, + STATUS_FRAME = 1, + CMDREP_FRAME = 2 + }; }; #endif // TIMEREPLICATORPROTOCOLBM_H diff --git a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h index f14808f..02457ce 100644 --- a/DeviceHub/protocol/dto/DeviceFrameBaseDto.h +++ b/DeviceHub/protocol/dto/DeviceFrameBaseDto.h @@ -19,6 +19,8 @@ QString devCode; QString frameType; // 帧类型 + QString commandId; + virtual QJsonObject toJSON() = 0; signals: diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp new file mode 100644 index 0000000..cb6a8ed --- /dev/null +++ b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp @@ -0,0 +1,20 @@ +#include "TimeReplicatorCmdRepDto.h" + +TimeReplicatorCmdRepDto::TimeReplicatorCmdRepDto(QObject *parent) : DeviceFrameBaseDto(parent) +{ + +} + +QJsonObject TimeReplicatorCmdRepDto::toJSON() +{ + QJsonObject jsonObj; + + jsonObj.insert("status", QString::number(this->cmdStatus)); + jsonObj.insert("commandId", this->commandId); + if (this->cmdStatus != 1) + { + jsonObj.insert("remarks", "failed"); + } + + return jsonObj; +} diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h new file mode 100644 index 0000000..c74f54d --- /dev/null +++ b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h @@ -0,0 +1,24 @@ +#ifndef TIMEREPLICATORCMDREPDTO_H +#define TIMEREPLICATORCMDREPDTO_H + +#include + +#include "DeviceFrameBaseDto.h" + +class TimeReplicatorCmdRepDto : public DeviceFrameBaseDto +{ + Q_OBJECT +public: + explicit TimeReplicatorCmdRepDto(QObject *parent = nullptr); + + qint8 cmdStatus; + QString remarks; + + QJsonObject toJSON() override; + +signals: + +public slots: +}; + +#endif // TIMEREPLICATORCMDREPDTO_H diff --git a/DeviceHub/protocol/protocol.pri b/DeviceHub/protocol/protocol.pri index ddf5dcc..cddbb80 100644 --- a/DeviceHub/protocol/protocol.pri +++ b/DeviceHub/protocol/protocol.pri @@ -12,6 +12,7 @@ HEADERS += $$PWD/dto/FreqSwitcherStatusDto.h HEADERS += $$PWD/dto/BCodeTerminalStatusDto.h HEADERS += $$PWD/dto/TimeReplicatorStatusDto.h +HEADERS += $$PWD/dto/TimeReplicatorCmdRepDto.h HEADERS += $$PWD/dto/FreqReplicatorStatusDto.h HEADERS += $$PWD/DeviceProtocolBase.h @@ -34,6 +35,7 @@ SOURCES += $$PWD/dto/TimeSwitcherInterfaceDto.cpp SOURCES += $$PWD/dto/FreqSwitcherInterfaceDto.cpp SOURCES += $$PWD/dto/TimeReplicatorStatusDto.cpp +SOURCES += $$PWD/dto/TimeReplicatorCmdRepDto.cpp SOURCES += $$PWD/dto/FreqSwitcherStatusDto.cpp SOURCES += $$PWD/DeviceProtocolBase.cpp SOURCES += $$PWD/FrequencyTuningProtocolBM.cpp