diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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 fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index a4a6571..32e1e6c 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -53,6 +53,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void TimeSwitcher::dataBReceivedHandler(QByteArray data)
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -167,7 +173,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -209,7 +215,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index a4a6571..32e1e6c 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -53,6 +53,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void TimeSwitcher::dataBReceivedHandler(QByteArray data)
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -167,7 +173,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -209,7 +215,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
index a88d372..9c696af 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
@@ -13,39 +13,48 @@
// 解析数据
bool BCodeTerminalProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType)
{
- if (frameType != 1)
- return false;
-
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
- QByteArray content = rawData.mid(19, length - 24);
- int outBdcByte = 0;
- int outBacByte = 0;
- QString outStr = "";
-
- ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
- ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
- ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
- ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
-
- outBdcByte = content.mid(6, 1).toInt(0, 16);
- outBacByte = content.mid(5, 1).toInt(0, 16);
- for (int i = 0; i < 4; i++)
+ if (frameType == BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
{
- ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
- ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+ qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
+ QByteArray content = rawData.mid(19, length - 24);
+ int outBdcByte = 0;
+ int outBacByte = 0;
+ QString outStr = "";
- outBdcByte = outBdcByte / 2;
- outBacByte = outBacByte / 2;
+ ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
+ ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
+ ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
+ ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
+
+ outBdcByte = content.mid(6, 1).toInt(0, 16);
+ outBacByte = content.mid(5, 1).toInt(0, 16);
+ for (int i = 0; i < 4; i++)
+ {
+ ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
+ ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+
+ outBdcByte = outBdcByte / 2;
+ outBacByte = outBacByte / 2;
+ }
+
+ ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
+ ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
+ ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
+ ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
+
+ ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+
+ return true;
}
-
- ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
- ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
- ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
- ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
-
- ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
-
- return true;
+ return false;
}
QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
@@ -56,7 +65,26 @@
commandBytes.append("1304-20").append(0x20);
commandBytes.append(devCode);
commandBytes.append(commandType);
- commandBytes.append(valueSet.replace(",", ""));
+ if (commandType == "1")
+ {
+ commandBytes.append(valueSet);
+ } else if (commandType == "2")
+ {
+ QStringList valueList = valueSet.split(",");
+ if (valueList.at(0).size() > 4)
+ {
+ commandBytes.append(valueList.at(0).right(4));
+ } else if (valueList.at(0).size() < 4)
+ {
+ commandBytes.append(4 - valueList.at(0).size(), '0');
+ commandBytes.append(valueList.at(0));
+ } else
+ {
+ commandBytes.append(valueList.at(0));
+ }
+
+ commandBytes.append(valueList.at(1).right(1));
+ }
commandBytes.append(this->buildCRC16(commandBytes));
commandBytes.append("*");
@@ -68,7 +96,20 @@
DeviceFrameBaseDto * BCodeTerminalProtocolBM::frameFactory(int frameType)
{
- DeviceFrameBaseDto * frameData = new BCodeTerminalStatusDto();
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME :
+ frameData = new BCodeTerminalStatusDto();
+ break;
+
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
return frameData;
}
@@ -80,7 +121,10 @@
while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true)
{
QByteArray ba;
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ int start = rawData.indexOf("$");
+ int end = rawData.indexOf("*", start);
+ qint8 length = end - start + 1;
+// qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
{
ba.append(rawData.mid(0, length));
@@ -99,9 +143,16 @@
// 检测帧格式,帧头帧尾
int BCodeTerminalProtocolBM::checkFrame(QByteArray rawData)
{
- if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
- rawData.at(3) == '2' && rawData.at(20) == '2' && //
- rawData.size() == rawData.mid(1, 2).toInt(0, 16))
- return 1;
- return 0;
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*')
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME;
+ }
+ }
+
+ return BCODE_TERMINAL_FRAME_TYPE::UNKNOW_FRAME;
}
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index a4a6571..32e1e6c 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -53,6 +53,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void TimeSwitcher::dataBReceivedHandler(QByteArray data)
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -167,7 +173,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -209,7 +215,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
index a88d372..9c696af 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
@@ -13,39 +13,48 @@
// 解析数据
bool BCodeTerminalProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType)
{
- if (frameType != 1)
- return false;
-
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
- QByteArray content = rawData.mid(19, length - 24);
- int outBdcByte = 0;
- int outBacByte = 0;
- QString outStr = "";
-
- ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
- ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
- ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
- ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
-
- outBdcByte = content.mid(6, 1).toInt(0, 16);
- outBacByte = content.mid(5, 1).toInt(0, 16);
- for (int i = 0; i < 4; i++)
+ if (frameType == BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
{
- ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
- ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+ qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
+ QByteArray content = rawData.mid(19, length - 24);
+ int outBdcByte = 0;
+ int outBacByte = 0;
+ QString outStr = "";
- outBdcByte = outBdcByte / 2;
- outBacByte = outBacByte / 2;
+ ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
+ ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
+ ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
+ ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
+
+ outBdcByte = content.mid(6, 1).toInt(0, 16);
+ outBacByte = content.mid(5, 1).toInt(0, 16);
+ for (int i = 0; i < 4; i++)
+ {
+ ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
+ ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+
+ outBdcByte = outBdcByte / 2;
+ outBacByte = outBacByte / 2;
+ }
+
+ ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
+ ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
+ ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
+ ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
+
+ ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+
+ return true;
}
-
- ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
- ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
- ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
- ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
-
- ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
-
- return true;
+ return false;
}
QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
@@ -56,7 +65,26 @@
commandBytes.append("1304-20").append(0x20);
commandBytes.append(devCode);
commandBytes.append(commandType);
- commandBytes.append(valueSet.replace(",", ""));
+ if (commandType == "1")
+ {
+ commandBytes.append(valueSet);
+ } else if (commandType == "2")
+ {
+ QStringList valueList = valueSet.split(",");
+ if (valueList.at(0).size() > 4)
+ {
+ commandBytes.append(valueList.at(0).right(4));
+ } else if (valueList.at(0).size() < 4)
+ {
+ commandBytes.append(4 - valueList.at(0).size(), '0');
+ commandBytes.append(valueList.at(0));
+ } else
+ {
+ commandBytes.append(valueList.at(0));
+ }
+
+ commandBytes.append(valueList.at(1).right(1));
+ }
commandBytes.append(this->buildCRC16(commandBytes));
commandBytes.append("*");
@@ -68,7 +96,20 @@
DeviceFrameBaseDto * BCodeTerminalProtocolBM::frameFactory(int frameType)
{
- DeviceFrameBaseDto * frameData = new BCodeTerminalStatusDto();
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME :
+ frameData = new BCodeTerminalStatusDto();
+ break;
+
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
return frameData;
}
@@ -80,7 +121,10 @@
while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true)
{
QByteArray ba;
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ int start = rawData.indexOf("$");
+ int end = rawData.indexOf("*", start);
+ qint8 length = end - start + 1;
+// qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
{
ba.append(rawData.mid(0, length));
@@ -99,9 +143,16 @@
// 检测帧格式,帧头帧尾
int BCodeTerminalProtocolBM::checkFrame(QByteArray rawData)
{
- if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
- rawData.at(3) == '2' && rawData.at(20) == '2' && //
- rawData.size() == rawData.mid(1, 2).toInt(0, 16))
- return 1;
- return 0;
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*')
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME;
+ }
+ }
+
+ return BCODE_TERMINAL_FRAME_TYPE::UNKNOW_FRAME;
}
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
index accebdd..e762d36 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
@@ -6,6 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/BCodeTerminalStatusDto.h"
+#include "dto/CommandReplyDto.h"
class BCodeTerminalProtocolBM : public DeviceProtocolBase
{
@@ -24,6 +25,13 @@
// 检测帧格式,帧头帧尾
int checkFrame(QByteArray rawData);
+
+ enum BCODE_TERMINAL_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
};
#endif // BCODETERMINALPROTOCOLBM_H
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index a4a6571..32e1e6c 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -53,6 +53,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void TimeSwitcher::dataBReceivedHandler(QByteArray data)
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -167,7 +173,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -209,7 +215,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
index a88d372..9c696af 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
@@ -13,39 +13,48 @@
// 解析数据
bool BCodeTerminalProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType)
{
- if (frameType != 1)
- return false;
-
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
- QByteArray content = rawData.mid(19, length - 24);
- int outBdcByte = 0;
- int outBacByte = 0;
- QString outStr = "";
-
- ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
- ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
- ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
- ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
-
- outBdcByte = content.mid(6, 1).toInt(0, 16);
- outBacByte = content.mid(5, 1).toInt(0, 16);
- for (int i = 0; i < 4; i++)
+ if (frameType == BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
{
- ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
- ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+ qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
+ QByteArray content = rawData.mid(19, length - 24);
+ int outBdcByte = 0;
+ int outBacByte = 0;
+ QString outStr = "";
- outBdcByte = outBdcByte / 2;
- outBacByte = outBacByte / 2;
+ ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
+ ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
+ ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
+ ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
+
+ outBdcByte = content.mid(6, 1).toInt(0, 16);
+ outBacByte = content.mid(5, 1).toInt(0, 16);
+ for (int i = 0; i < 4; i++)
+ {
+ ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
+ ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+
+ outBdcByte = outBdcByte / 2;
+ outBacByte = outBacByte / 2;
+ }
+
+ ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
+ ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
+ ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
+ ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
+
+ ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+
+ return true;
}
-
- ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
- ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
- ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
- ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
-
- ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
-
- return true;
+ return false;
}
QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
@@ -56,7 +65,26 @@
commandBytes.append("1304-20").append(0x20);
commandBytes.append(devCode);
commandBytes.append(commandType);
- commandBytes.append(valueSet.replace(",", ""));
+ if (commandType == "1")
+ {
+ commandBytes.append(valueSet);
+ } else if (commandType == "2")
+ {
+ QStringList valueList = valueSet.split(",");
+ if (valueList.at(0).size() > 4)
+ {
+ commandBytes.append(valueList.at(0).right(4));
+ } else if (valueList.at(0).size() < 4)
+ {
+ commandBytes.append(4 - valueList.at(0).size(), '0');
+ commandBytes.append(valueList.at(0));
+ } else
+ {
+ commandBytes.append(valueList.at(0));
+ }
+
+ commandBytes.append(valueList.at(1).right(1));
+ }
commandBytes.append(this->buildCRC16(commandBytes));
commandBytes.append("*");
@@ -68,7 +96,20 @@
DeviceFrameBaseDto * BCodeTerminalProtocolBM::frameFactory(int frameType)
{
- DeviceFrameBaseDto * frameData = new BCodeTerminalStatusDto();
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME :
+ frameData = new BCodeTerminalStatusDto();
+ break;
+
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
return frameData;
}
@@ -80,7 +121,10 @@
while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true)
{
QByteArray ba;
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ int start = rawData.indexOf("$");
+ int end = rawData.indexOf("*", start);
+ qint8 length = end - start + 1;
+// qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
{
ba.append(rawData.mid(0, length));
@@ -99,9 +143,16 @@
// 检测帧格式,帧头帧尾
int BCodeTerminalProtocolBM::checkFrame(QByteArray rawData)
{
- if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
- rawData.at(3) == '2' && rawData.at(20) == '2' && //
- rawData.size() == rawData.mid(1, 2).toInt(0, 16))
- return 1;
- return 0;
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*')
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME;
+ }
+ }
+
+ return BCODE_TERMINAL_FRAME_TYPE::UNKNOW_FRAME;
}
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
index accebdd..e762d36 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
@@ -6,6 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/BCodeTerminalStatusDto.h"
+#include "dto/CommandReplyDto.h"
class BCodeTerminalProtocolBM : public DeviceProtocolBase
{
@@ -24,6 +25,13 @@
// 检测帧格式,帧头帧尾
int checkFrame(QByteArray rawData);
+
+ enum BCODE_TERMINAL_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
};
#endif // BCODETERMINALPROTOCOLBM_H
diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
index 359c0ce..a338f39 100644
--- a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
+++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
@@ -97,8 +97,22 @@
QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData)
{
QList resultList;
- if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+ int start = rawData.indexOf("$GL");
+ if (start < 0)
{
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("\r\n");
+ if (end < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.left(end);
+
+// if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+// {
QByteArray ba;
for (int i = 0; i < rawData.size() - 1; i++)
{
@@ -119,7 +133,7 @@
}
}
}
- }
+// }
return resultList;
}
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index a4a6571..32e1e6c 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -53,6 +53,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void TimeSwitcher::dataBReceivedHandler(QByteArray data)
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -167,7 +173,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -209,7 +215,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
index a88d372..9c696af 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
@@ -13,39 +13,48 @@
// 解析数据
bool BCodeTerminalProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType)
{
- if (frameType != 1)
- return false;
-
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
- QByteArray content = rawData.mid(19, length - 24);
- int outBdcByte = 0;
- int outBacByte = 0;
- QString outStr = "";
-
- ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
- ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
- ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
- ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
-
- outBdcByte = content.mid(6, 1).toInt(0, 16);
- outBacByte = content.mid(5, 1).toInt(0, 16);
- for (int i = 0; i < 4; i++)
+ if (frameType == BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
{
- ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
- ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+ qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
+ QByteArray content = rawData.mid(19, length - 24);
+ int outBdcByte = 0;
+ int outBacByte = 0;
+ QString outStr = "";
- outBdcByte = outBdcByte / 2;
- outBacByte = outBacByte / 2;
+ ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
+ ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
+ ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
+ ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
+
+ outBdcByte = content.mid(6, 1).toInt(0, 16);
+ outBacByte = content.mid(5, 1).toInt(0, 16);
+ for (int i = 0; i < 4; i++)
+ {
+ ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
+ ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+
+ outBdcByte = outBdcByte / 2;
+ outBacByte = outBacByte / 2;
+ }
+
+ ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
+ ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
+ ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
+ ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
+
+ ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+
+ return true;
}
-
- ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
- ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
- ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
- ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
-
- ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
-
- return true;
+ return false;
}
QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
@@ -56,7 +65,26 @@
commandBytes.append("1304-20").append(0x20);
commandBytes.append(devCode);
commandBytes.append(commandType);
- commandBytes.append(valueSet.replace(",", ""));
+ if (commandType == "1")
+ {
+ commandBytes.append(valueSet);
+ } else if (commandType == "2")
+ {
+ QStringList valueList = valueSet.split(",");
+ if (valueList.at(0).size() > 4)
+ {
+ commandBytes.append(valueList.at(0).right(4));
+ } else if (valueList.at(0).size() < 4)
+ {
+ commandBytes.append(4 - valueList.at(0).size(), '0');
+ commandBytes.append(valueList.at(0));
+ } else
+ {
+ commandBytes.append(valueList.at(0));
+ }
+
+ commandBytes.append(valueList.at(1).right(1));
+ }
commandBytes.append(this->buildCRC16(commandBytes));
commandBytes.append("*");
@@ -68,7 +96,20 @@
DeviceFrameBaseDto * BCodeTerminalProtocolBM::frameFactory(int frameType)
{
- DeviceFrameBaseDto * frameData = new BCodeTerminalStatusDto();
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME :
+ frameData = new BCodeTerminalStatusDto();
+ break;
+
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
return frameData;
}
@@ -80,7 +121,10 @@
while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true)
{
QByteArray ba;
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ int start = rawData.indexOf("$");
+ int end = rawData.indexOf("*", start);
+ qint8 length = end - start + 1;
+// qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
{
ba.append(rawData.mid(0, length));
@@ -99,9 +143,16 @@
// 检测帧格式,帧头帧尾
int BCodeTerminalProtocolBM::checkFrame(QByteArray rawData)
{
- if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
- rawData.at(3) == '2' && rawData.at(20) == '2' && //
- rawData.size() == rawData.mid(1, 2).toInt(0, 16))
- return 1;
- return 0;
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*')
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME;
+ }
+ }
+
+ return BCODE_TERMINAL_FRAME_TYPE::UNKNOW_FRAME;
}
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
index accebdd..e762d36 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
@@ -6,6 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/BCodeTerminalStatusDto.h"
+#include "dto/CommandReplyDto.h"
class BCodeTerminalProtocolBM : public DeviceProtocolBase
{
@@ -24,6 +25,13 @@
// 检测帧格式,帧头帧尾
int checkFrame(QByteArray rawData);
+
+ enum BCODE_TERMINAL_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
};
#endif // BCODETERMINALPROTOCOLBM_H
diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
index 359c0ce..a338f39 100644
--- a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
+++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
@@ -97,8 +97,22 @@
QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData)
{
QList resultList;
- if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+ int start = rawData.indexOf("$GL");
+ if (start < 0)
{
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("\r\n");
+ if (end < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.left(end);
+
+// if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+// {
QByteArray ba;
for (int i = 0; i < rawData.size() - 1; i++)
{
@@ -119,7 +133,7 @@
}
}
}
- }
+// }
return resultList;
}
diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp
index 38929a3..2356821 100644
--- a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp
+++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp
@@ -101,8 +101,22 @@
QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData)
{
QList resultList;
- if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+ int start = rawData.indexOf("$GL");
+ if (start < 0)
{
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("\r\n");
+ if (end < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.left(end);
+
+// if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+// {
QByteArray ba;
for (int i = 0; i < rawData.size() - 1; i++)
{
@@ -123,7 +137,7 @@
}
}
}
- }
+// }
return resultList;
}
diff --git a/DeviceHub/BCodeTerminalForm.cpp b/DeviceHub/BCodeTerminalForm.cpp
index fb4e74f..e3c6ba9 100644
--- a/DeviceHub/BCodeTerminalForm.cpp
+++ b/DeviceHub/BCodeTerminalForm.cpp
@@ -29,6 +29,14 @@
void BCodeTerminalForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0701")
{
@@ -92,3 +100,16 @@
}
}
+
+void BCodeTerminalForm::on_bctCmdRepButt_clicked()
+{
+ // 获取设备对象
+ int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex;
+ BCodeTerminal * device = (BCodeTerminal *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("07").at(devIndex);
+
+ // mock测试工作模式则产生一条mock数据
+ if (SettingConfig::getInstance().WORK_MODE == "mock")
+ {
+ device->mockReceivCmdReply();
+ }
+}
diff --git a/DeviceHub/BCodeTerminalForm.h b/DeviceHub/BCodeTerminalForm.h
index 0ae7601..0b54623 100644
--- a/DeviceHub/BCodeTerminalForm.h
+++ b/DeviceHub/BCodeTerminalForm.h
@@ -23,6 +23,8 @@
private slots:
void on_bctButt_clicked();
+ void on_bctCmdRepButt_clicked();
+
private:
Ui::BCodeTerminalForm *ui;
};
diff --git a/DeviceHub/BCodeTerminalForm.ui b/DeviceHub/BCodeTerminalForm.ui
index ec4c1cd..fdb2b26 100644
--- a/DeviceHub/BCodeTerminalForm.ui
+++ b/DeviceHub/BCodeTerminalForm.ui
@@ -507,6 +507,19 @@
+
+
+
+ 260
+ 20
+ 180
+ 40
+
+
+
+ Mock BCT CmdReply
+
+
diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp
index bd7d338..fc8a915 100644
--- a/DeviceHub/DeviceHubWindow.cpp
+++ b/DeviceHub/DeviceHubWindow.cpp
@@ -61,7 +61,13 @@
DeviceHubWindow::~DeviceHubWindow()
{
+ kafkaConsumer->exitThread();
+ kafkaConsumer->deleteLater();
+ kafkaConsumer->wait();
+
delete ui;
+
+ delete kafkaConsumer;
}
QComboBox * DeviceHubWindow::getDevTypeSelect()
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 94d64b0..54dc08a 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -29,6 +29,14 @@
void FreqSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0601")
{
diff --git a/DeviceHub/SignalGeneratorForm.cpp b/DeviceHub/SignalGeneratorForm.cpp
index f0feaa1..ad49262 100644
--- a/DeviceHub/SignalGeneratorForm.cpp
+++ b/DeviceHub/SignalGeneratorForm.cpp
@@ -29,6 +29,14 @@
void SignalGeneratorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0401")
{
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 8875231..9a1bac5 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -29,6 +29,14 @@
void TimeSwitcherForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData)
{
+ QString currentDevCode = ((DeviceHubWindow *)this->parent()->parent())->getDevSelect()->currentData().toJsonObject().find("deviceNo")->toString();
+
+ // 如果不是当前设备的帧,直接返回
+ if (frameData->devCode != currentDevCode)
+ {
+ return;
+ }
+
// 当前显示的设备编号
if (frameData->frameType == "0501")
{
diff --git a/DeviceHub/common/utils/QKafkaConsumer.cpp b/DeviceHub/common/utils/QKafkaConsumer.cpp
index c62f08e..cb4fe37 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.cpp
+++ b/DeviceHub/common/utils/QKafkaConsumer.cpp
@@ -69,6 +69,11 @@
}
}
+void QKafkaConsumer::exitThread()
+{
+ runFlag = false;
+}
+
void QKafkaConsumer::messageConsume(RdKafka::Message* message) {
const RdKafka::Headers *headers;
diff --git a/DeviceHub/common/utils/QKafkaConsumer.h b/DeviceHub/common/utils/QKafkaConsumer.h
index 745ad68..84f4702 100644
--- a/DeviceHub/common/utils/QKafkaConsumer.h
+++ b/DeviceHub/common/utils/QKafkaConsumer.h
@@ -17,6 +17,7 @@
int createConsumer();
void run();
+ void exitThread();
void messageConsume(RdKafka::Message * message);
diff --git a/DeviceHub/device/BCodeTerminal.cpp b/DeviceHub/device/BCodeTerminal.cpp
index a423a06..d52b5e2 100644
--- a/DeviceHub/device/BCodeTerminal.cpp
+++ b/DeviceHub/device/BCodeTerminal.cpp
@@ -35,16 +35,24 @@
QByteArray buffer;
// b-code terminal
- buffer.append("$2621304-20 210100112100f90210.035422*");
- buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
+ buffer.append("$2521304-20 210100112111ff1210.0311d0*");
+// buffer.append("$3e21304-20 2101001111304-20 2101001210801H.1.00S.1.030008432*");
this->dataReceivedHandler(buffer);
}
+void BCodeTerminal::mockReceivCmdReply()
+{
+ QByteArray buffer;
+
+ // bcode term
+ buffer.append("$1941308-20 21010021053d*");
+ this->dataReceivedHandler(buffer);
+}
+
void BCodeTerminal::dataReceivedHandler(QByteArray data)
{
this->dataBuff.append(data);
-
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
@@ -72,7 +80,17 @@
frameDto->devCode = devCode;
- this->afterFrameParse(frameDto);
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
+ {
+ this->afterFrameParse(frameDto);
+ }
+
+ if (frameType == BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ frameDto->rawCommand = rawCommandBytes;
+ frameDto->commandId = commandId;
+ this->afterCommandReply(frameDto);
+ }
}
// 在此处释放内存,不影响后续显示
@@ -86,15 +104,15 @@
void BCodeTerminal::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
// 1. 原始字节数组数据
QString filename = "raw_" + devCode + ".log";
- QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size() - FRAME_TAIL.size());
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
// 2. 解析后的json数据
@@ -107,6 +125,7 @@
{
QJsonObject jsonObj = frameDto->toJSON();
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ jsonObj.insert("master", SettingConfig::getInstance().MASTER);
jsonObj.insert("deviceId", deviceId);
kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
@@ -115,6 +134,29 @@
emit this->sendDataToDraw(frameDto);
}
+void BCodeTerminal::afterCommandReply(DeviceFrameBaseDto * frameDto)
+{
+ // 0. 输出到日志文件中
+ QString date = frameDto->timestamp.mid(0, 10);
+
+ // 1. 原始字节数组数据
+ QString filename = "raw_" + devCode + ".log";
+ QString content = frameDto->timestamp + " [recv] " + frameDto->rawFrame.left(frameDto->rawFrame.size());
+ QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = frameDto->timestamp + " [reply] " + QJsonDocument(frameDto->toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ QJsonObject jsonObj = frameDto->toJSON();
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ }
+}
+
void BCodeTerminal::sendDataToSerial(QByteArray data)
{
CommandReplyDto replyDto;
@@ -153,25 +195,10 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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;
}
@@ -193,7 +220,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/BCodeTerminal.h b/DeviceHub/device/BCodeTerminal.h
index 450cd8f..385869f 100644
--- a/DeviceHub/device/BCodeTerminal.h
+++ b/DeviceHub/device/BCodeTerminal.h
@@ -4,7 +4,9 @@
#include
#include "device/DeviceBase.h"
+#include "protocol/BCodeTerminalProtocolBM.h"
#include "protocol/dto/BCodeTerminalStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class BCodeTerminal : public DeviceBase
{
@@ -14,10 +16,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/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 552921b..f31d628 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -52,6 +52,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void FreqSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/SignalGenerator.cpp b/DeviceHub/device/SignalGenerator.cpp
index c653f21..a6dc0d9 100644
--- a/DeviceHub/device/SignalGenerator.cpp
+++ b/DeviceHub/device/SignalGenerator.cpp
@@ -55,6 +55,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void SignalGenerator::dataBReceivedHandler(QByteArray data)
@@ -65,6 +68,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -103,8 +109,8 @@
}
void SignalGenerator::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -169,7 +175,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -211,7 +217,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index a4a6571..32e1e6c 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -53,6 +53,9 @@
{
this->dataBuff.clear();
frameParse(frameList);
+ } else if (dataBuff.size() > 1024)
+ {
+ dataBuff.clear();
}
}
void TimeSwitcher::dataBReceivedHandler(QByteArray data)
@@ -63,6 +66,9 @@
{
this->dataBuffB.clear();
frameParse(frameListB);
+ } else if (dataBuffB.size() > 1024)
+ {
+ dataBuffB.clear();
}
}
@@ -101,8 +107,8 @@
}
void TimeSwitcher::afterFrameParse(DeviceFrameBaseDto * frameDto)
{
- std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
- std::cout << frameDto->rawFrame.toStdString() << std::endl;
+// std::cout << "frame type: " << typeid(* frameDto).name() << std::endl;
+// std::cout << frameDto->rawFrame.toStdString() << std::endl;
// 0. 输出到日志文件中
QString date = frameDto->timestamp.mid(0, 10);
@@ -167,7 +173,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "raw_" + devCode + ".log";
+ QString filename = "rawCmd_" + 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);
@@ -209,7 +215,7 @@
QString date = now.toString("yyyy-MM-dd");
// 1. 原始字节数组数据
- QString filename = "frame_" + devCode + ".log";
+ QString filename = "cmd_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
index a88d372..9c696af 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.cpp
@@ -13,39 +13,48 @@
// 解析数据
bool BCodeTerminalProtocolBM::parseDeviceFrameData(QByteArray rawData, DeviceFrameBaseDto * frameData, int frameType)
{
- if (frameType != 1)
- return false;
-
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
- QByteArray content = rawData.mid(19, length - 24);
- int outBdcByte = 0;
- int outBacByte = 0;
- QString outStr = "";
-
- ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
- ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
- ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
- ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
-
- outBdcByte = content.mid(6, 1).toInt(0, 16);
- outBacByte = content.mid(5, 1).toInt(0, 16);
- for (int i = 0; i < 4; i++)
+ if (frameType == BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME)
{
- ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
- ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+ qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
+ QByteArray content = rawData.mid(19, length - 24);
+ int outBdcByte = 0;
+ int outBacByte = 0;
+ QString outStr = "";
- outBdcByte = outBdcByte / 2;
- outBacByte = outBacByte / 2;
+ ((BCodeTerminalStatusDto *) frameData)->devStatus = content.at(0);
+ ((BCodeTerminalStatusDto *) frameData)->bdcInStatus = content.at(2);
+ ((BCodeTerminalStatusDto *) frameData)->bacInStatus = content.at(3);
+ ((BCodeTerminalStatusDto *) frameData)->fiveInStatus = content.at(4);
+
+ outBdcByte = content.mid(6, 1).toInt(0, 16);
+ outBacByte = content.mid(5, 1).toInt(0, 16);
+ for (int i = 0; i < 4; i++)
+ {
+ ((BCodeTerminalStatusDto *) frameData)->bdcOutStatusList.append(QString("%1").arg(outBdcByte % 2));
+ ((BCodeTerminalStatusDto *) frameData)->bacOutStatusList.append(QString("%1").arg(outBacByte % 2));
+
+ outBdcByte = outBdcByte / 2;
+ outBacByte = outBacByte / 2;
+ }
+
+ ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
+ ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
+ ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
+ ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
+
+ ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
+
+ return true;
+ } else if (frameType == BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME)
+ {
+ qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ QByteArray content = rawData.mid(length - 6, 1);
+
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+
+ return true;
}
-
- ((BCodeTerminalStatusDto *) frameData)->ref = content.at(7);
- ((BCodeTerminalStatusDto *) frameData)->track = content.at(8);
- ((BCodeTerminalStatusDto *) frameData)->bacRange = content.mid(9, 4).toFloat();
- ((BCodeTerminalStatusDto *) frameData)->bacRatio = content.mid(13, 1).toInt();
-
- ((BCodeTerminalStatusDto *)frameData)->frameType = B_CODE_TERMINAL_STATUS_FRAME_TYPE;
-
- return true;
+ return false;
}
QByteArray BCodeTerminalProtocolBM::generateSettingCommand(QString devCode, QString commandType, QString valueSet)
@@ -56,7 +65,26 @@
commandBytes.append("1304-20").append(0x20);
commandBytes.append(devCode);
commandBytes.append(commandType);
- commandBytes.append(valueSet.replace(",", ""));
+ if (commandType == "1")
+ {
+ commandBytes.append(valueSet);
+ } else if (commandType == "2")
+ {
+ QStringList valueList = valueSet.split(",");
+ if (valueList.at(0).size() > 4)
+ {
+ commandBytes.append(valueList.at(0).right(4));
+ } else if (valueList.at(0).size() < 4)
+ {
+ commandBytes.append(4 - valueList.at(0).size(), '0');
+ commandBytes.append(valueList.at(0));
+ } else
+ {
+ commandBytes.append(valueList.at(0));
+ }
+
+ commandBytes.append(valueList.at(1).right(1));
+ }
commandBytes.append(this->buildCRC16(commandBytes));
commandBytes.append("*");
@@ -68,7 +96,20 @@
DeviceFrameBaseDto * BCodeTerminalProtocolBM::frameFactory(int frameType)
{
- DeviceFrameBaseDto * frameData = new BCodeTerminalStatusDto();
+ DeviceFrameBaseDto * frameData = 0;
+ switch (frameType) {
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME :
+ frameData = new BCodeTerminalStatusDto();
+ break;
+
+ case BCodeTerminalProtocolBM::BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME :
+ frameData = new CommandReplyDto();
+ break;
+
+ default:
+ frameData = nullptr;
+ break;
+ }
return frameData;
}
@@ -80,7 +121,10 @@
while (rawData.endsWith(QByteArray("*")) == true && rawData.startsWith("$") == true)
{
QByteArray ba;
- qint8 length = rawData.mid(1, 2).toInt(0, 16);
+ int start = rawData.indexOf("$");
+ int end = rawData.indexOf("*", start);
+ qint8 length = end - start + 1;
+// qint8 length = rawData.mid(1, 2).toInt(0, 16) + 1;
if (rawData.at(0) == '$' && rawData.at(length - 1) == '*')
{
ba.append(rawData.mid(0, length));
@@ -99,9 +143,16 @@
// 检测帧格式,帧头帧尾
int BCodeTerminalProtocolBM::checkFrame(QByteArray rawData)
{
- if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*' &&
- rawData.at(3) == '2' && rawData.at(20) == '2' && //
- rawData.size() == rawData.mid(1, 2).toInt(0, 16))
- return 1;
- return 0;
+ if (rawData.at(0) == '$' && rawData.at(rawData.size() - 1) == '*')
+ {
+ if (rawData.at(3) == '2' && rawData.at(20) == '2')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::STATUS_FRAME;
+ } else if (rawData.at(3) == '4')
+ {
+ return BCODE_TERMINAL_FRAME_TYPE::CMDREP_FRAME;
+ }
+ }
+
+ return BCODE_TERMINAL_FRAME_TYPE::UNKNOW_FRAME;
}
diff --git a/DeviceHub/protocol/BCodeTerminalProtocolBM.h b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
index accebdd..e762d36 100644
--- a/DeviceHub/protocol/BCodeTerminalProtocolBM.h
+++ b/DeviceHub/protocol/BCodeTerminalProtocolBM.h
@@ -6,6 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/BCodeTerminalStatusDto.h"
+#include "dto/CommandReplyDto.h"
class BCodeTerminalProtocolBM : public DeviceProtocolBase
{
@@ -24,6 +25,13 @@
// 检测帧格式,帧头帧尾
int checkFrame(QByteArray rawData);
+
+ enum BCODE_TERMINAL_FRAME_TYPE
+ {
+ UNKNOW_FRAME = 0,
+ STATUS_FRAME = 1,
+ CMDREP_FRAME = 2
+ };
};
#endif // BCODETERMINALPROTOCOLBM_H
diff --git a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
index 359c0ce..a338f39 100644
--- a/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
+++ b/DeviceHub/protocol/FreqSwitcherProtocolBM.cpp
@@ -97,8 +97,22 @@
QList FreqSwitcherProtocolBM::extractFrameList(QByteArray rawData)
{
QList resultList;
- if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+ int start = rawData.indexOf("$GL");
+ if (start < 0)
{
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("\r\n");
+ if (end < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.left(end);
+
+// if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+// {
QByteArray ba;
for (int i = 0; i < rawData.size() - 1; i++)
{
@@ -119,7 +133,7 @@
}
}
}
- }
+// }
return resultList;
}
diff --git a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp
index 38929a3..2356821 100644
--- a/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp
+++ b/DeviceHub/protocol/SignalGeneratorProtocolBM.cpp
@@ -101,8 +101,22 @@
QList SignalGeneratorProtocolBM::extractFrameList(QByteArray rawData)
{
QList resultList;
- if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+ int start = rawData.indexOf("$GL");
+ if (start < 0)
{
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("\r\n");
+ if (end < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.left(end);
+
+// if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+// {
QByteArray ba;
for (int i = 0; i < rawData.size() - 1; i++)
{
@@ -123,7 +137,7 @@
}
}
}
- }
+// }
return resultList;
}
diff --git a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp
index 7691d83..dff6b42 100644
--- a/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeSwitcherProtocolBM.cpp
@@ -93,8 +93,22 @@
QList TimeSwitcherProtocolBM::extractFrameList(QByteArray rawData)
{
QList resultList;
- if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+ int start = rawData.indexOf("$GL");
+ if (start < 0)
{
+ return resultList;
+ }
+ rawData = rawData.right(rawData.size() - start);
+
+ int end = rawData.lastIndexOf("\r\n");
+ if (end < 0)
+ {
+ return resultList;
+ }
+ rawData = rawData.left(end);
+
+// if (rawData.endsWith(QByteArray("\r\n")) == true && rawData.startsWith("$") == true)
+// {
QByteArray ba;
for (int i = 0; i < rawData.size() - 1; i++)
{
@@ -115,7 +129,7 @@
}
}
}
- }
+// }
return resultList;
}