diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
index 405cd74..98282be 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
@@ -6,7 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/TimeReplicatorStatusDto.h"
-#include "dto/TimeReplicatorCmdRepDto.h"
+#include "dto/CommandReplyDto.h"
class TimeReplicatorProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
index 405cd74..98282be 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
@@ -6,7 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/TimeReplicatorStatusDto.h"
-#include "dto/TimeReplicatorCmdRepDto.h"
+#include "dto/CommandReplyDto.h"
class TimeReplicatorProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.cpp b/DeviceHub/protocol/dto/CommandReplyDto.cpp
new file mode 100644
index 0000000..e4fc52f
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.cpp
@@ -0,0 +1,21 @@
+#include "CommandReplyDto.h"
+
+CommandReplyDto::CommandReplyDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject CommandReplyDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ jsonObj.insert("status", QString::number(this->cmdStatus));
+ jsonObj.insert("commandId", this->commandId);
+ if (this->cmdStatus != 1)
+ {
+ jsonObj.insert("remarks", remarks);
+ }
+ jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
+
+ return jsonObj;
+}
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
index 405cd74..98282be 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
@@ -6,7 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/TimeReplicatorStatusDto.h"
-#include "dto/TimeReplicatorCmdRepDto.h"
+#include "dto/CommandReplyDto.h"
class TimeReplicatorProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.cpp b/DeviceHub/protocol/dto/CommandReplyDto.cpp
new file mode 100644
index 0000000..e4fc52f
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.cpp
@@ -0,0 +1,21 @@
+#include "CommandReplyDto.h"
+
+CommandReplyDto::CommandReplyDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject CommandReplyDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ jsonObj.insert("status", QString::number(this->cmdStatus));
+ jsonObj.insert("commandId", this->commandId);
+ if (this->cmdStatus != 1)
+ {
+ jsonObj.insert("remarks", remarks);
+ }
+ jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.h b/DeviceHub/protocol/dto/CommandReplyDto.h
new file mode 100644
index 0000000..1db3ce5
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.h
@@ -0,0 +1,24 @@
+#ifndef COMMANDREPLYDTO_H
+#define COMMANDREPLYDTO_H
+
+#include
+
+#include "DeviceFrameBaseDto.h"
+
+class CommandReplyDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit CommandReplyDto(QObject *parent = nullptr);
+
+ qint8 cmdStatus;
+ QString remarks;
+
+ QJsonObject toJSON() override;
+
+signals:
+
+public slots:
+};
+
+#endif // COMMANDREPLYDTO_H
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
index 405cd74..98282be 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
@@ -6,7 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/TimeReplicatorStatusDto.h"
-#include "dto/TimeReplicatorCmdRepDto.h"
+#include "dto/CommandReplyDto.h"
class TimeReplicatorProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.cpp b/DeviceHub/protocol/dto/CommandReplyDto.cpp
new file mode 100644
index 0000000..e4fc52f
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.cpp
@@ -0,0 +1,21 @@
+#include "CommandReplyDto.h"
+
+CommandReplyDto::CommandReplyDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject CommandReplyDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ jsonObj.insert("status", QString::number(this->cmdStatus));
+ jsonObj.insert("commandId", this->commandId);
+ if (this->cmdStatus != 1)
+ {
+ jsonObj.insert("remarks", remarks);
+ }
+ jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.h b/DeviceHub/protocol/dto/CommandReplyDto.h
new file mode 100644
index 0000000..1db3ce5
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.h
@@ -0,0 +1,24 @@
+#ifndef COMMANDREPLYDTO_H
+#define COMMANDREPLYDTO_H
+
+#include
+
+#include "DeviceFrameBaseDto.h"
+
+class CommandReplyDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit CommandReplyDto(QObject *parent = nullptr);
+
+ qint8 cmdStatus;
+ QString remarks;
+
+ QJsonObject toJSON() override;
+
+signals:
+
+public slots:
+};
+
+#endif // COMMANDREPLYDTO_H
diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp
deleted file mode 100644
index 038f004..0000000
--- a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "TimeReplicatorCmdRepDto.h"
-
-TimeReplicatorCmdRepDto::TimeReplicatorCmdRepDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject TimeReplicatorCmdRepDto::toJSON()
-{
- QJsonObject jsonObj;
-
- jsonObj.insert("status", QString::number(this->cmdStatus));
- jsonObj.insert("commandId", this->commandId);
- if (this->cmdStatus != 1)
- {
- jsonObj.insert("remarks", remarks);
- }
- jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
-
- return jsonObj;
-}
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
index 405cd74..98282be 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
@@ -6,7 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/TimeReplicatorStatusDto.h"
-#include "dto/TimeReplicatorCmdRepDto.h"
+#include "dto/CommandReplyDto.h"
class TimeReplicatorProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.cpp b/DeviceHub/protocol/dto/CommandReplyDto.cpp
new file mode 100644
index 0000000..e4fc52f
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.cpp
@@ -0,0 +1,21 @@
+#include "CommandReplyDto.h"
+
+CommandReplyDto::CommandReplyDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject CommandReplyDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ jsonObj.insert("status", QString::number(this->cmdStatus));
+ jsonObj.insert("commandId", this->commandId);
+ if (this->cmdStatus != 1)
+ {
+ jsonObj.insert("remarks", remarks);
+ }
+ jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.h b/DeviceHub/protocol/dto/CommandReplyDto.h
new file mode 100644
index 0000000..1db3ce5
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.h
@@ -0,0 +1,24 @@
+#ifndef COMMANDREPLYDTO_H
+#define COMMANDREPLYDTO_H
+
+#include
+
+#include "DeviceFrameBaseDto.h"
+
+class CommandReplyDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit CommandReplyDto(QObject *parent = nullptr);
+
+ qint8 cmdStatus;
+ QString remarks;
+
+ QJsonObject toJSON() override;
+
+signals:
+
+public slots:
+};
+
+#endif // COMMANDREPLYDTO_H
diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp
deleted file mode 100644
index 038f004..0000000
--- a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "TimeReplicatorCmdRepDto.h"
-
-TimeReplicatorCmdRepDto::TimeReplicatorCmdRepDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject TimeReplicatorCmdRepDto::toJSON()
-{
- QJsonObject jsonObj;
-
- jsonObj.insert("status", QString::number(this->cmdStatus));
- jsonObj.insert("commandId", this->commandId);
- if (this->cmdStatus != 1)
- {
- jsonObj.insert("remarks", remarks);
- }
- jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
-
- return jsonObj;
-}
diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h
deleted file mode 100644
index c74f54d..0000000
--- a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef TIMEREPLICATORCMDREPDTO_H
-#define TIMEREPLICATORCMDREPDTO_H
-
-#include
-
-#include "DeviceFrameBaseDto.h"
-
-class TimeReplicatorCmdRepDto : public DeviceFrameBaseDto
-{
- Q_OBJECT
-public:
- explicit TimeReplicatorCmdRepDto(QObject *parent = nullptr);
-
- qint8 cmdStatus;
- QString remarks;
-
- QJsonObject toJSON() override;
-
-signals:
-
-public slots:
-};
-
-#endif // TIMEREPLICATORCMDREPDTO_H
diff --git a/DeviceHub/FreqSwitcherForm.cpp b/DeviceHub/FreqSwitcherForm.cpp
index 55d83c0..dc1a111 100644
--- a/DeviceHub/FreqSwitcherForm.cpp
+++ b/DeviceHub/FreqSwitcherForm.cpp
@@ -28,6 +28,7 @@
if (frameData->frameType == "0601")
{
FreqSwitcherStatusDto * statusFrameDto = (FreqSwitcherStatusDto *) frameData;
+ ui->label_ts->setText(statusFrameDto->timestamp);
ui->fsDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->fsLockPhaseType->setText(statusFrameDto->lockPhaseType == "1" ? "自由运行" : "跟踪");
QString lockPhaseStatusStr;
diff --git a/DeviceHub/FreqSwitcherForm.ui b/DeviceHub/FreqSwitcherForm.ui
index 9395f2a..9a7ca41 100644
--- a/DeviceHub/FreqSwitcherForm.ui
+++ b/DeviceHub/FreqSwitcherForm.ui
@@ -900,6 +900,25 @@
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeReplicatorForm.cpp b/DeviceHub/TimeReplicatorForm.cpp
index 22a78fc..ed0f51c 100644
--- a/DeviceHub/TimeReplicatorForm.cpp
+++ b/DeviceHub/TimeReplicatorForm.cpp
@@ -55,6 +55,7 @@
TimeReplicatorStatusDto * statusFrameDto = (TimeReplicatorStatusDto *) frameData;
ui->trDevStatus->setText(statusFrameDto->devStatus == "1" ? "正常" : "异常");
ui->trInCount->setText(QString("%1").arg(statusFrameDto->inCount));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeReplicatorForm.ui b/DeviceHub/TimeReplicatorForm.ui
index d65fb8f..755d183 100644
--- a/DeviceHub/TimeReplicatorForm.ui
+++ b/DeviceHub/TimeReplicatorForm.ui
@@ -193,6 +193,25 @@
MockTR CmdReply
+
+
+
+ 110
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/TimeSwitcherForm.cpp b/DeviceHub/TimeSwitcherForm.cpp
index 4d18f0c..8875231 100644
--- a/DeviceHub/TimeSwitcherForm.cpp
+++ b/DeviceHub/TimeSwitcherForm.cpp
@@ -39,6 +39,7 @@
ui->tsOppsPhaseAccOut->setText(QString("%1 ps").arg(statusFrameDto->oppsPhaseAccOut));
ui->tsBacRatio->setText(QString("%1").arg(statusFrameDto->bacRatio));
ui->tsBacRange->setText(QString("%1 V").arg(statusFrameDto->bacRange));
+ ui->label_ts->setText(statusFrameDto->timestamp);
QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject();
QJsonDocument doc;
diff --git a/DeviceHub/TimeSwitcherForm.ui b/DeviceHub/TimeSwitcherForm.ui
index 71477c4..067dffa 100644
--- a/DeviceHub/TimeSwitcherForm.ui
+++ b/DeviceHub/TimeSwitcherForm.ui
@@ -871,6 +871,25 @@
true
+
+
+
+ 100
+ 80
+ 300
+ 30
+
+
+
+
+ 微软雅黑
+ 12
+
+
+
+
+
+
diff --git a/DeviceHub/device/FreqSwitcher.cpp b/DeviceHub/device/FreqSwitcher.cpp
index 0fd0785..abfe7f1 100644
--- a/DeviceHub/device/FreqSwitcher.cpp
+++ b/DeviceHub/device/FreqSwitcher.cpp
@@ -49,11 +49,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,34 @@
void FreqSwitcher::sendDataToSerial(QByteArray data)
{
+ CommandReplyDto replyDto;
+ replyDto.devCode = devCode;
+ replyDto.commandId = commandId;
+ replyDto.rawCommand = rawCommandBytes;
+
data.append(FRAME_TAIL);
+ if (SettingConfig::getInstance().WORK_MODE == "real")
+ {
+ if (serialUtil.isOpen() == true)
+ {
+ this->serialUtil.sendData(data);
+ } else if (serialUtilB.isOpen() == true)
+ {
+ this->serialUtilB.sendData(data);
+ } else
+ {
+ replyDto.cmdStatus = 0;
+ replyDto.remarks = "serialport not avilable";
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+ return;
+ }
+ }
this->serialUtil.sendData(data);
// 记录日志
@@ -133,22 +158,39 @@
QString filename = "raw_" + devCode + ".log";
QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + data.left(data.size() - FRAME_TAIL.size());
QLogUtil::writeRawDataLogByDate(date, filename, content);
+
+ // reply success
+ replyDto.cmdStatus = 1;
+
+ // 2. 解析后的json数据
+ QString frameFilename = "frame_" + devCode + ".log";
+ QString frameContent = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [reply] " + QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact);
+ QLogUtil::writeChannelDataLogByDate(date, frameFilename, frameContent);
+
+ // 3. 输出到中间件,执行后续处理过程
+ if (SettingConfig::getInstance().NEED_KAFKA == 1)
+ {
+ kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC,
+ QString(QJsonDocument(replyDto.toJSON()).toJson(QJsonDocument::Compact)));
+ }
+
+ std::cout << content.toStdString() << std::endl;
}
void FreqSwitcher::commandReceivedHandler(QJsonObject command)
{
if (command.contains("deviceType") == false || command.value("deviceType").toString() != "06")
{
- std::cout << "device type [" << command.value("deviceType").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
if (command.contains("deviceId") == false || command.value("deviceId").toString() != deviceId)
{
- std::cout << "deviceId [" << command.value("deviceId").toString().toStdString() << "] not matched. return" << std::endl;
return;
}
+ std::cout << QString(QJsonDocument(command).toJson(QJsonDocument::Compact)).toStdString() << std::endl;
+
// 记录日志
// 0. 输出到日志文件中
QDateTime now = QDateTime::currentDateTime();
@@ -156,18 +198,14 @@
// 1. 原始字节数组数据
QString filename = "frame_" + devCode + ".log";
- QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [send] " + command.find("cmdStr")->toString();
+ QString content = now.toString("yyyy-MM-dd HH:mm:ss.zzz") + " [recv] " + command.find("cmdStr")->toString();
QLogUtil::writeChannelDataLogByDate(date, filename, content);
QByteArray commandBytes = protocol->generateSettingCommand(devCode, command.value("command").toString(), command.value("params").toString());
- this->sendDataToSerial(commandBytes);
command.insert("rawCommand", QString::fromUtf8(commandBytes));
-
- QJsonObject cmdcb;
- cmdcb.insert("commandId", command.value("commandId").toString());
- cmdcb.insert("rawCommand", QString::fromUtf8(commandBytes));
- cmdcb.insert("status", "1");
- this->kafkaProducer.produceMessage(SettingConfig::getInstance().KAFKA_CMDCB_TOPIC, QString(QJsonDocument(cmdcb).toJson(QJsonDocument::Compact)));
+ this->commandId = command.value("commandId").toString();
+ this->rawCommandBytes = commandBytes;
+ this->sendDataToSerial(commandBytes);
// display on page
emit sendCommandToDisplay(command);
diff --git a/DeviceHub/device/FreqSwitcher.h b/DeviceHub/device/FreqSwitcher.h
index f073f4d..0051c1c 100644
--- a/DeviceHub/device/FreqSwitcher.h
+++ b/DeviceHub/device/FreqSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/FreqSwitcherInterfaceDto.h"
#include "protocol/dto/FreqSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class FreqSwitcher : public DeviceBase
{
diff --git a/DeviceHub/device/TimeReplicator.cpp b/DeviceHub/device/TimeReplicator.cpp
index 2fab078..b5f67e9 100644
--- a/DeviceHub/device/TimeReplicator.cpp
+++ b/DeviceHub/device/TimeReplicator.cpp
@@ -178,7 +178,7 @@
this->serialUtilB.sendData(data);
} else
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeReplicator.h b/DeviceHub/device/TimeReplicator.h
index d903490..1383fac 100644
--- a/DeviceHub/device/TimeReplicator.h
+++ b/DeviceHub/device/TimeReplicator.h
@@ -6,7 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/TimeReplicatorProtocolBM.h"
#include "protocol/dto/TimeReplicatorStatusDto.h"
-#include "protocol/dto/TimeReplicatorCmdRepDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeReplicator : public DeviceBase
{
diff --git a/DeviceHub/device/TimeSwitcher.cpp b/DeviceHub/device/TimeSwitcher.cpp
index 40e7b35..7bcdc0e 100644
--- a/DeviceHub/device/TimeSwitcher.cpp
+++ b/DeviceHub/device/TimeSwitcher.cpp
@@ -50,11 +50,9 @@
std::cout << dataBuff.toStdString() << std::endl;
QList frameList = protocol->extractFrameList(this->dataBuff);
-
- this->dataBuff.clear();
-
if (frameList.size() > 0)
{
+ this->dataBuff.clear();
for (int i = 0; i < frameList.size(); i++)
{
QByteArray frameByte = frameList.at(i);
@@ -121,7 +119,7 @@
void TimeSwitcher::sendDataToSerial(QByteArray data)
{
- TimeReplicatorCmdRepDto replyDto;
+ CommandReplyDto replyDto;
replyDto.devCode = devCode;
replyDto.commandId = commandId;
replyDto.rawCommand = rawCommandBytes;
diff --git a/DeviceHub/device/TimeSwitcher.h b/DeviceHub/device/TimeSwitcher.h
index a48cd9d..6ad76c4 100644
--- a/DeviceHub/device/TimeSwitcher.h
+++ b/DeviceHub/device/TimeSwitcher.h
@@ -6,6 +6,7 @@
#include "device/DeviceBase.h"
#include "protocol/dto/TimeSwitcherInterfaceDto.h"
#include "protocol/dto/TimeSwitcherStatusDto.h"
+#include "protocol/dto/CommandReplyDto.h"
class TimeSwitcher : public DeviceBase
{
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
index 4200297..06acc1b 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.cpp
@@ -57,7 +57,7 @@
qint8 length = rawData.mid(1, 2).toInt(0, 16);
QByteArray content = rawData.mid(length - 6, 1);
- ((TimeReplicatorCmdRepDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
+ ((CommandReplyDto *)frameData)->cmdStatus = content == "1" ? 1 : 0;
return true;
}
@@ -135,7 +135,7 @@
break;
case TimeReplicatorProtocolBM::TIME_REPLICATOR_FRAME_TYPE::CMDREP_FRAME :
- frameData = new TimeReplicatorCmdRepDto();
+ frameData = new CommandReplyDto();
break;
default:
diff --git a/DeviceHub/protocol/TimeReplicatorProtocolBM.h b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
index 405cd74..98282be 100644
--- a/DeviceHub/protocol/TimeReplicatorProtocolBM.h
+++ b/DeviceHub/protocol/TimeReplicatorProtocolBM.h
@@ -6,7 +6,7 @@
#include "common/utils/QByteUtil.h"
#include "DeviceProtocolBase.h"
#include "dto/TimeReplicatorStatusDto.h"
-#include "dto/TimeReplicatorCmdRepDto.h"
+#include "dto/CommandReplyDto.h"
class TimeReplicatorProtocolBM : public DeviceProtocolBase
{
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.cpp b/DeviceHub/protocol/dto/CommandReplyDto.cpp
new file mode 100644
index 0000000..e4fc52f
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.cpp
@@ -0,0 +1,21 @@
+#include "CommandReplyDto.h"
+
+CommandReplyDto::CommandReplyDto(QObject *parent) : DeviceFrameBaseDto(parent)
+{
+
+}
+
+QJsonObject CommandReplyDto::toJSON()
+{
+ QJsonObject jsonObj;
+
+ jsonObj.insert("status", QString::number(this->cmdStatus));
+ jsonObj.insert("commandId", this->commandId);
+ if (this->cmdStatus != 1)
+ {
+ jsonObj.insert("remarks", remarks);
+ }
+ jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
+
+ return jsonObj;
+}
diff --git a/DeviceHub/protocol/dto/CommandReplyDto.h b/DeviceHub/protocol/dto/CommandReplyDto.h
new file mode 100644
index 0000000..1db3ce5
--- /dev/null
+++ b/DeviceHub/protocol/dto/CommandReplyDto.h
@@ -0,0 +1,24 @@
+#ifndef COMMANDREPLYDTO_H
+#define COMMANDREPLYDTO_H
+
+#include
+
+#include "DeviceFrameBaseDto.h"
+
+class CommandReplyDto : public DeviceFrameBaseDto
+{
+ Q_OBJECT
+public:
+ explicit CommandReplyDto(QObject *parent = nullptr);
+
+ qint8 cmdStatus;
+ QString remarks;
+
+ QJsonObject toJSON() override;
+
+signals:
+
+public slots:
+};
+
+#endif // COMMANDREPLYDTO_H
diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp
deleted file mode 100644
index 038f004..0000000
--- a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "TimeReplicatorCmdRepDto.h"
-
-TimeReplicatorCmdRepDto::TimeReplicatorCmdRepDto(QObject *parent) : DeviceFrameBaseDto(parent)
-{
-
-}
-
-QJsonObject TimeReplicatorCmdRepDto::toJSON()
-{
- QJsonObject jsonObj;
-
- jsonObj.insert("status", QString::number(this->cmdStatus));
- jsonObj.insert("commandId", this->commandId);
- if (this->cmdStatus != 1)
- {
- jsonObj.insert("remarks", remarks);
- }
- jsonObj.insert("rawCommand", QString::fromUtf8(rawCommand));
-
- return jsonObj;
-}
diff --git a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h b/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h
deleted file mode 100644
index c74f54d..0000000
--- a/DeviceHub/protocol/dto/TimeReplicatorCmdRepDto.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef TIMEREPLICATORCMDREPDTO_H
-#define TIMEREPLICATORCMDREPDTO_H
-
-#include
-
-#include "DeviceFrameBaseDto.h"
-
-class TimeReplicatorCmdRepDto : public DeviceFrameBaseDto
-{
- Q_OBJECT
-public:
- explicit TimeReplicatorCmdRepDto(QObject *parent = nullptr);
-
- qint8 cmdStatus;
- QString remarks;
-
- QJsonObject toJSON() override;
-
-signals:
-
-public slots:
-};
-
-#endif // TIMEREPLICATORCMDREPDTO_H
diff --git a/DeviceHub/protocol/protocol.pri b/DeviceHub/protocol/protocol.pri
index cddbb80..a792cf0 100644
--- a/DeviceHub/protocol/protocol.pri
+++ b/DeviceHub/protocol/protocol.pri
@@ -12,8 +12,8 @@
HEADERS += $$PWD/dto/FreqSwitcherStatusDto.h
HEADERS += $$PWD/dto/BCodeTerminalStatusDto.h
HEADERS += $$PWD/dto/TimeReplicatorStatusDto.h
-HEADERS += $$PWD/dto/TimeReplicatorCmdRepDto.h
HEADERS += $$PWD/dto/FreqReplicatorStatusDto.h
+HEADERS += $$PWD/dto/CommandReplyDto.h
HEADERS += $$PWD/DeviceProtocolBase.h
HEADERS += $$PWD/FrequencyTuningProtocolBM.h
@@ -35,8 +35,8 @@
SOURCES += $$PWD/dto/TimeSwitcherInterfaceDto.cpp
SOURCES += $$PWD/dto/FreqSwitcherInterfaceDto.cpp
SOURCES += $$PWD/dto/TimeReplicatorStatusDto.cpp
-SOURCES += $$PWD/dto/TimeReplicatorCmdRepDto.cpp
SOURCES += $$PWD/dto/FreqSwitcherStatusDto.cpp
+SOURCES += $$PWD/dto/CommandReplyDto.cpp
SOURCES += $$PWD/DeviceProtocolBase.cpp
SOURCES += $$PWD/FrequencyTuningProtocolBM.cpp
SOURCES += $$PWD/SignalGeneratorProtocolBM.cpp