diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} + void sendDataToSerial(QByteArray data) {} signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 223819d..c653f21 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,6 +8,8 @@ this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &SignalGenerator::dataBReceivedHandler); connect(this, &SignalGenerator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); @@ -48,48 +50,57 @@ void SignalGenerator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void SignalGenerator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void SignalGenerator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -123,8 +134,34 @@ void SignalGenerator::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -135,22 +172,39 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void SignalGenerator::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } + std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl; + // 记录日志 // 0. 输出到日志文件中 QDateTime now = QDateTime::currentDateTime(); @@ -158,18 +212,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 223819d..c653f21 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,6 +8,8 @@ this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &SignalGenerator::dataBReceivedHandler); connect(this, &SignalGenerator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); @@ -48,48 +50,57 @@ void SignalGenerator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void SignalGenerator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void SignalGenerator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -123,8 +134,34 @@ void SignalGenerator::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -135,22 +172,39 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void SignalGenerator::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } + std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl; + // 记录日志 // 0. 输出到日志文件中 QDateTime now = QDateTime::currentDateTime(); @@ -158,18 +212,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 9a49fdd..613d52a 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,11 +16,13 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -29,6 +31,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 223819d..c653f21 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,6 +8,8 @@ this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &SignalGenerator::dataBReceivedHandler); connect(this, &SignalGenerator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); @@ -48,48 +50,57 @@ void SignalGenerator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void SignalGenerator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void SignalGenerator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -123,8 +134,34 @@ void SignalGenerator::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -135,22 +172,39 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void SignalGenerator::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } + std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl; + // 记录日志 // 0. 输出到日志文件中 QDateTime now = QDateTime::currentDateTime(); @@ -158,18 +212,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 9a49fdd..613d52a 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,11 +16,13 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -29,6 +31,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index b5f67e9..92a1433 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -9,6 +9,8 @@ this->devType = "09"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeReplicator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &TimeReplicator::dataBReceivedHandler); connect(this, &TimeReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->timeRepForm, &TimeReplicatorForm::drawDeviceFrameOnForm); @@ -64,56 +66,66 @@ void TimeReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - frameDto->devCode = devCode; - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) - { - this->afterFrameParse(frameDto); - } - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) - { - frameDto->rawCommand = rawCommandBytes; - frameDto->commandId = commandId; - this->afterCommandReply(frameDto); - } - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + frameParse(frameList); + } +} +void TimeReplicator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void TimeReplicator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + frameDto->devCode = devCode; + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->rawCommand = rawCommandBytes; + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void TimeReplicator::afterFrameParse(DeviceFrameBaseDto * frameDto) { // 0. 输出到日志文件中 diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 223819d..c653f21 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,6 +8,8 @@ this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &SignalGenerator::dataBReceivedHandler); connect(this, &SignalGenerator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); @@ -48,48 +50,57 @@ void SignalGenerator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void SignalGenerator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void SignalGenerator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -123,8 +134,34 @@ void SignalGenerator::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -135,22 +172,39 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void SignalGenerator::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } + std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl; + // 记录日志 // 0. 输出到日志文件中 QDateTime now = QDateTime::currentDateTime(); @@ -158,18 +212,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 9a49fdd..613d52a 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,11 +16,13 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -29,6 +31,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index b5f67e9..92a1433 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -9,6 +9,8 @@ this->devType = "09"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeReplicator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &TimeReplicator::dataBReceivedHandler); connect(this, &TimeReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->timeRepForm, &TimeReplicatorForm::drawDeviceFrameOnForm); @@ -64,56 +66,66 @@ void TimeReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - frameDto->devCode = devCode; - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) - { - this->afterFrameParse(frameDto); - } - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) - { - frameDto->rawCommand = rawCommandBytes; - frameDto->commandId = commandId; - this->afterCommandReply(frameDto); - } - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + frameParse(frameList); + } +} +void TimeReplicator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void TimeReplicator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + frameDto->devCode = devCode; + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->rawCommand = rawCommandBytes; + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void TimeReplicator::afterFrameParse(DeviceFrameBaseDto * frameDto) { // 0. 输出到日志文件中 diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index 1383fac..3d57a76 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -15,6 +15,8 @@ explicit TimeReplicator(QObject *parent = nullptr); ~TimeReplicator(); + void frameParse(QList frameList); + void mockReceivData(); void mockReceivCmdReply(); @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 223819d..c653f21 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,6 +8,8 @@ this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &SignalGenerator::dataBReceivedHandler); connect(this, &SignalGenerator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); @@ -48,48 +50,57 @@ void SignalGenerator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void SignalGenerator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void SignalGenerator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -123,8 +134,34 @@ void SignalGenerator::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -135,22 +172,39 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void SignalGenerator::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } + std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl; + // 记录日志 // 0. 输出到日志文件中 QDateTime now = QDateTime::currentDateTime(); @@ -158,18 +212,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 9a49fdd..613d52a 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,11 +16,13 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -29,6 +31,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index b5f67e9..92a1433 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -9,6 +9,8 @@ this->devType = "09"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeReplicator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &TimeReplicator::dataBReceivedHandler); connect(this, &TimeReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->timeRepForm, &TimeReplicatorForm::drawDeviceFrameOnForm); @@ -64,56 +66,66 @@ void TimeReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - frameDto->devCode = devCode; - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) - { - this->afterFrameParse(frameDto); - } - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) - { - frameDto->rawCommand = rawCommandBytes; - frameDto->commandId = commandId; - this->afterCommandReply(frameDto); - } - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + frameParse(frameList); + } +} +void TimeReplicator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void TimeReplicator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + frameDto->devCode = devCode; + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->rawCommand = rawCommandBytes; + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void TimeReplicator::afterFrameParse(DeviceFrameBaseDto * frameDto) { // 0. 输出到日志文件中 diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index 1383fac..3d57a76 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -15,6 +15,8 @@ explicit TimeReplicator(QObject *parent = nullptr); ~TimeReplicator(); + void frameParse(QList frameList); + void mockReceivData(); void mockReceivCmdReply(); @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index 7bcdc0e..a4a6571 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &TimeSwitcher::dataBReceivedHandler); connect(this, &TimeSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); @@ -46,46 +48,57 @@ void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + frameParse(frameList); + } +} +void TimeSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void TimeSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp index ff620a0..fb4e74f 100644 --- a/DeviceHub/BCodeTerminalForm.cpp +++ b/DeviceHub/BCodeTerminalForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->btBACInStatus->setText(statusFrameDto->bacInStatus == "1" ? "有效" : statusFrameDto->bacInStatus == "2" ? "异常" : "无效"); ui->btFiveInStatus->setText(statusFrameDto->fiveInStatus == "1" ? "有效" : statusFrameDto->fiveInStatus == "2" ? "异常" : "无效"); ui->btRef->setText(statusFrameDto->ref == "0" ? "BDC" : statusFrameDto->ref == "1" ? "BAC" : "5M"); + ui->label_ts->setText(statusFrameDto->timestamp); QString trackStatusStr; if (statusFrameDto->track == "0") trackStatusStr = "自由"; else if (statusFrameDto->track == "1") trackStatusStr = "跟踪"; diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui index 29dae63..ec4c1cd 100644 --- a/DeviceHub/BCodeTerminalForm.ui +++ b/DeviceHub/BCodeTerminalForm.ui @@ -488,6 +488,25 @@ + + + + 110 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp index dc1a111..94d64b0 100644 --- a/DeviceHub/FreqSwitcherForm.cpp +++ b/DeviceHub/FreqSwitcherForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqSwitcher * device = (FreqSwitcher *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("06").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) diff --git a/DeviceHub/FrequencyTuningForm.cpp b/DeviceHub/FrequencyTuningForm.cpp index 8e04da6..668458a 100644 --- a/DeviceHub/FrequencyTuningForm.cpp +++ b/DeviceHub/FrequencyTuningForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FrequencyTuning * device = (FrequencyTuning *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("03").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FrequencyTuningForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -33,6 +38,7 @@ ui->ftInputTimeType->setText(freqFrameDto->inputTimeType == "1" ? "5MHz" : "10MHz"); ui->ftFreqAdjustAcc->setText(QString("%1 pHz").arg(freqFrameDto->freqAdjustAcc)); ui->ftPulseAdjustAcc->setText(QString("%1 fs").arg((float) freqFrameDto->pulseAdjustAcc * 0.1)); + ui->label_ts->setText(freqFrameDto->timestamp); } else if (frameData->frameType == "0302") { FrequencyTuningStatusPulseDto * pulseFrameDto = (FrequencyTuningStatusPulseDto *) frameData; diff --git a/DeviceHub/FrequencyTuningForm.ui b/DeviceHub/FrequencyTuningForm.ui index 3bd9184..8f01816 100644 --- a/DeviceHub/FrequencyTuningForm.ui +++ b/DeviceHub/FrequencyTuningForm.ui @@ -697,6 +697,25 @@ send + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp index 8961771..f0feaa1 100644 --- a/DeviceHub/SignalGeneratorForm.cpp +++ b/DeviceHub/SignalGeneratorForm.cpp @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; SignalGenerator * device = (SignalGenerator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("04").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -44,6 +49,7 @@ ui->sgPhaseShiftAcc->setText(QString("%1 ps").arg(statusFrameDto->phaseShiftAcc)); ui->sgBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio)); ui->sgBacRange->setText(QString("%1").arg(statusFrameDto->bacRange)); + ui->label_ts->setText(statusFrameDto->timestamp); } else if (frameData->frameType == "0403") { SignalGeneratorMJDTimeDto * mjdFrameDto = (SignalGeneratorMJDTimeDto *) frameData; diff --git a/DeviceHub/SignalGeneratorForm.ui b/DeviceHub/SignalGeneratorForm.ui index edd892e..506e935 100644 --- a/DeviceHub/SignalGeneratorForm.ui +++ b/DeviceHub/SignalGeneratorForm.ui @@ -1385,6 +1385,25 @@ + + + + 100 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp index 5329676..a423a06 100644 --- a/DeviceHub/device/BCodeTerminal.cpp +++ b/DeviceHub/device/BCodeTerminal.cpp @@ -48,9 +48,9 @@ std::cout << dataBuff.toStdString() << std::endl; QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -117,8 +117,35 @@ void BCodeTerminal::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } + // 记录日志 // 0. 输出到日志文件中 @@ -129,19 +156,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void BCodeTerminal::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "07") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -152,18 +194,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h index 7c32c09..450cd8f 100644 --- a/DeviceHub/device/BCodeTerminal.h +++ b/DeviceHub/device/BCodeTerminal.h @@ -14,10 +14,10 @@ ~BCodeTerminal(); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index a8d033b..363f640 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -41,9 +41,7 @@ void FreqReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 5353c0b..e119917 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -16,11 +16,11 @@ void frameParse(QList frameList); void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; - void sendDataToSerial(QByteArray data) {}; + 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 abfe7f1..552921b 100644 --- a/DeviceHub/device/FreqSwitcher.cpp +++ b/DeviceHub/device/FreqSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "06"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FreqSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FreqSwitcher::dataBReceivedHandler); connect(this, &FreqSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqSwitForm, &FreqSwitcherForm::drawDeviceFrameOnForm); @@ -45,46 +47,58 @@ void FreqSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { - this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); } } +void FreqSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); + } +} + +void FreqSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h index 0051c1c..57e9971 100644 --- a/DeviceHub/device/FreqSwitcher.h +++ b/DeviceHub/device/FreqSwitcher.h @@ -15,11 +15,13 @@ explicit FreqSwitcher(QObject *parent = nullptr); ~FreqSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply() {}; + void mockReceivCmdReply() {} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto) {}; + void afterCommandReply(DeviceFrameBaseDto * frameDto) {} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/FrequencyTuning.cpp b/DeviceHub/device/FrequencyTuning.cpp index 640dc6a..ea31920 100644 --- a/DeviceHub/device/FrequencyTuning.cpp +++ b/DeviceHub/device/FrequencyTuning.cpp @@ -8,6 +8,8 @@ this->devType = "03"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &FrequencyTuning::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &FrequencyTuning::dataBReceivedHandler); connect(this, &FrequencyTuning::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqTunForm, &FrequencyTuningForm::drawDeviceFrameOnForm); @@ -45,48 +47,57 @@ void FrequencyTuning::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void FrequencyTuning::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void FrequencyTuning::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void FrequencyTuning::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -120,8 +131,34 @@ void FrequencyTuning::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -132,19 +169,34 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void FrequencyTuning::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "03") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } @@ -155,18 +207,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/FrequencyTuning.h b/DeviceHub/device/FrequencyTuning.h index 5ede354..cdfa1fa 100644 --- a/DeviceHub/device/FrequencyTuning.h +++ b/DeviceHub/device/FrequencyTuning.h @@ -14,11 +14,13 @@ explicit FrequencyTuning(QObject *parent = nullptr); ~FrequencyTuning(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -27,6 +29,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp index 223819d..c653f21 100644 --- a/DeviceHub/device/SignalGenerator.cpp +++ b/DeviceHub/device/SignalGenerator.cpp @@ -8,6 +8,8 @@ this->devType = "04"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &SignalGenerator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &SignalGenerator::dataBReceivedHandler); connect(this, &SignalGenerator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->signGenForm, &SignalGeneratorForm::drawDeviceFrameOnForm); @@ -48,48 +50,57 @@ void SignalGenerator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - - this->dataBuff.clear(); - if (frameList.size() > 0) { - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + this->dataBuff.clear(); + frameParse(frameList); + } +} +void SignalGenerator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void SignalGenerator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; @@ -123,8 +134,34 @@ void SignalGenerator::sendDataToSerial(QByteArray data) { + CommandReplyDto replyDto; + replyDto.devCode = devCode; + replyDto.commandId = commandId; + replyDto.rawCommand = rawCommandBytes; + data.append(FRAME_TAIL); - this->serialUtil.sendData(data); + if (SettingConfig::getInstance().WORK_MODE == "real") + { + if (serialUtil.isOpen() == true) + { + this->serialUtil.sendData(data); + } else if (serialUtilB.isOpen() == true) + { + this->serialUtilB.sendData(data); + } else + { + replyDto.cmdStatus = 0; + replyDto.remarks = "serialport not avilable"; + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + return; + } + } // 记录日志 // 0. 输出到日志文件中 @@ -135,22 +172,39 @@ QString filename = "raw_" + devCode + ".log"; QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size()); QLogUtil::writeRawDataLogByDate(date, filename, content); + + // reply success + replyDto.cmdStatus = 1; + + // 2. 解析后的json数据 + QString frameFilename = "frame_" + devCode + ".log"; + QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact); + QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent); + + // 3. 输出到中间件,执行后续处理过程 + if (SettingConfig::getInstance().NEED_KAFKA == 1) + { + kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, + QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact))); + } + + std::cout << content.toStdString() << std::endl; } void SignalGenerator::commandReceivedHandler(QJsonObject command) { if (command.contains("deviceType") == false || command.value("deviceType").toString() != "04") { - std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl; return; } if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId) { - std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl; return; } + std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl; + // 记录日志 // 0. 输出到日志文件中 QDateTime now = QDateTime::currentDateTime(); @@ -158,18 +212,14 @@ // 1. 原始字节数组数据 QString filename = "frame_" + devCode + ".log"; - QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString(); + QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString(); QLogUtil::writeChannelDataLogByDate(date, filename, content); QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString()); - this->sendDataToSerial(commandBytes); command.insert("rawCommand", QString::fromUtf8(commandBytes)); - - 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))); + this->commandId = command.value("commandId").toString(); + this->rawCommandBytes = commandBytes; + this->sendDataToSerial(commandBytes); // display on page emit sendCommandToDisplay(command); diff --git a/DeviceHub/device/SignalGenerator.h b/DeviceHub/device/SignalGenerator.h index 9a49fdd..613d52a 100644 --- a/DeviceHub/device/SignalGenerator.h +++ b/DeviceHub/device/SignalGenerator.h @@ -16,11 +16,13 @@ explicit SignalGenerator(QObject *parent = nullptr); ~SignalGenerator(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -29,6 +31,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp index b5f67e9..92a1433 100644 --- a/DeviceHub/device/TimeReplicator.cpp +++ b/DeviceHub/device/TimeReplicator.cpp @@ -9,6 +9,8 @@ this->devType = "09"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeReplicator::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &TimeReplicator::dataBReceivedHandler); connect(this, &TimeReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->timeRepForm, &TimeReplicatorForm::drawDeviceFrameOnForm); @@ -64,56 +66,66 @@ void TimeReplicator::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); - if (frameList.size() > 0) { this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - frameDto->devCode = devCode; - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) - { - this->afterFrameParse(frameDto); - } - - if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) - { - frameDto->rawCommand = rawCommandBytes; - frameDto->commandId = commandId; - this->afterCommandReply(frameDto); - } - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + frameParse(frameList); + } +} +void TimeReplicator::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void TimeReplicator::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + frameDto->devCode = devCode; + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::STATUS_FRAME) + { + this->afterFrameParse(frameDto); + } + + if (frameType == TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME) + { + frameDto->rawCommand = rawCommandBytes; + frameDto->commandId = commandId; + this->afterCommandReply(frameDto); + } + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void TimeReplicator::afterFrameParse(DeviceFrameBaseDto * frameDto) { // 0. 输出到日志文件中 diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h index 1383fac..3d57a76 100644 --- a/DeviceHub/device/TimeReplicator.h +++ b/DeviceHub/device/TimeReplicator.h @@ -15,6 +15,8 @@ explicit TimeReplicator(QObject *parent = nullptr); ~TimeReplicator(); + void frameParse(QList frameList); + void mockReceivData(); void mockReceivCmdReply(); @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); }; diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp index 7bcdc0e..a4a6571 100644 --- a/DeviceHub/device/TimeSwitcher.cpp +++ b/DeviceHub/device/TimeSwitcher.cpp @@ -8,6 +8,8 @@ this->devType = "05"; connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &TimeSwitcher::dataReceivedHandler); + connect(&this->serialUtilB, &QSerialPortUtil::dataRecieved, + this, &TimeSwitcher::dataBReceivedHandler); connect(this, &TimeSwitcher::sendDataToDraw, ((DeviceHubWindow *)this->parent())->tmSwitForm, &TimeSwitcherForm::drawDeviceFrameOnForm); @@ -46,46 +48,57 @@ void TimeSwitcher::dataReceivedHandler(QByteArray data) { this->dataBuff.append(data); - - std::cout << dataBuff.toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { this->dataBuff.clear(); - for (int i = 0; i < frameList.size(); i++) - { - QByteArray frameByte = frameList.at(i); - - int frameType = protocol->checkFrame(frameByte); - DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); - if (frameDto != nullptr) - { - // ★解析成数据对象 - bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); - - // 解析成功 - if (parse == true) - { - QDateTime now = QDateTime::currentDateTime(); - frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); - frameDto->milisecond = now.toMSecsSinceEpoch(); - frameDto->rawFrame = frameByte; - - frameDto->devCode = devCode; - - this->afterFrameParse(frameDto); - } - - // 在此处释放内存,不影响后续显示 - // 不在此处释放内存则会导致内存持续增加 - // 具体原因不明 - delete frameDto; - } - } + frameParse(frameList); + } +} +void TimeSwitcher::dataBReceivedHandler(QByteArray data) +{ + this->dataBuffB.append(data); + QList frameListB = protocol->extractFrameList(this->dataBuffB); + if (frameListB.size() > 0) + { + this->dataBuffB.clear(); + frameParse(frameListB); } } +void TimeSwitcher::frameParse(QList frameList) +{ + for (int i = 0; i < frameList.size(); i++) + { + QByteArray frameByte = frameList.at(i); + + int frameType = protocol->checkFrame(frameByte); + DeviceFrameBaseDto * frameDto = protocol->frameFactory(frameType); + if (frameDto != nullptr) + { + // ★解析成数据对象 + bool parse = protocol->parseDeviceFrameData(frameByte, frameDto, frameType); + + // 解析成功 + if (parse == true) + { + QDateTime now = QDateTime::currentDateTime(); + frameDto->timestamp = now.toString("yyyy-MM-dd HH:mm:ss.zzz"); + frameDto->milisecond = now.toMSecsSinceEpoch(); + frameDto->rawFrame = frameByte; + + frameDto->devCode = devCode; + + this->afterFrameParse(frameDto); + } + + // 在此处释放内存,不影响后续显示 + // 不在此处释放内存则会导致内存持续增加 + // 具体原因不明 + delete frameDto; + } + } +} void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto) { std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h index 6ad76c4..82e900f 100644 --- a/DeviceHub/device/TimeSwitcher.h +++ b/DeviceHub/device/TimeSwitcher.h @@ -15,11 +15,13 @@ explicit TimeSwitcher(QObject *parent = nullptr); ~TimeSwitcher(); + void frameParse(QList frameList); + void mockReceivData(); - void mockReceivCmdReply(){}; + void mockReceivCmdReply(){} void afterFrameParse(DeviceFrameBaseDto * frameDto); - void afterCommandReply(DeviceFrameBaseDto * frameDto){}; + void afterCommandReply(DeviceFrameBaseDto * frameDto){} void sendDataToSerial(QByteArray data); signals: @@ -28,6 +30,7 @@ public slots: void dataReceivedHandler(QByteArray data); + void dataBReceivedHandler(QByteArray data); void commandReceivedHandler(QJsonObject command); };