diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/PhaseCompAcq/common/utils/SettingConfig.cpp b/PhaseCompAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.cpp
+++ b/PhaseCompAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/PhaseCompAcq/common/utils/SettingConfig.cpp b/PhaseCompAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.cpp
+++ b/PhaseCompAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/PhaseCompAcq/common/utils/SettingConfig.h b/PhaseCompAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.h
+++ b/PhaseCompAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/PhaseCompAcq/common/utils/SettingConfig.cpp b/PhaseCompAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.cpp
+++ b/PhaseCompAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/PhaseCompAcq/common/utils/SettingConfig.h b/PhaseCompAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.h
+++ b/PhaseCompAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/PhaseCompAcq/conf/config.ini b/PhaseCompAcq/conf/config.ini
index 46d97d7..a65af8b 100644
--- a/PhaseCompAcq/conf/config.ini
+++ b/PhaseCompAcq/conf/config.ini
@@ -3,15 +3,17 @@
[kafka]
needKafka=1
-brokers="111.198.10.15:12502"
+brokers="111.198.10.15:20104"
dataTopic="cppTest"
-needSasl=0
-sasl.username="admin"
-sasl.password="casicss"
+statusTopic="dev-status"
+needSasl=1
+saslUsername="admin"
+saslPassword="casicss"
[client]
clientId="phase"
appKey="bd593bdd20943d2db8af217c3712a460"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/PhaseCompAcq/common/utils/SettingConfig.cpp b/PhaseCompAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.cpp
+++ b/PhaseCompAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/PhaseCompAcq/common/utils/SettingConfig.h b/PhaseCompAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.h
+++ b/PhaseCompAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/PhaseCompAcq/conf/config.ini b/PhaseCompAcq/conf/config.ini
index 46d97d7..a65af8b 100644
--- a/PhaseCompAcq/conf/config.ini
+++ b/PhaseCompAcq/conf/config.ini
@@ -3,15 +3,17 @@
[kafka]
needKafka=1
-brokers="111.198.10.15:12502"
+brokers="111.198.10.15:20104"
dataTopic="cppTest"
-needSasl=0
-sasl.username="admin"
-sasl.password="casicss"
+statusTopic="dev-status"
+needSasl=1
+saslUsername="admin"
+saslPassword="casicss"
[client]
clientId="phase"
appKey="bd593bdd20943d2db8af217c3712a460"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp b/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
index 5163335..cd39a40 100644
--- a/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
+++ b/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
@@ -19,3 +19,23 @@
return jsonObj;
}
+
+QJsonObject PhaseDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ QJsonArray channelActiveArray;
+ for (int i = 0; i < channelActive.size(); i++)
+ {
+ channelActiveArray.append(channelActive.at(i));
+ }
+ dataObj.insert("channelActive", channelActiveArray);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0201");
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/PhaseCompAcq/common/utils/SettingConfig.cpp b/PhaseCompAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.cpp
+++ b/PhaseCompAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/PhaseCompAcq/common/utils/SettingConfig.h b/PhaseCompAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.h
+++ b/PhaseCompAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/PhaseCompAcq/conf/config.ini b/PhaseCompAcq/conf/config.ini
index 46d97d7..a65af8b 100644
--- a/PhaseCompAcq/conf/config.ini
+++ b/PhaseCompAcq/conf/config.ini
@@ -3,15 +3,17 @@
[kafka]
needKafka=1
-brokers="111.198.10.15:12502"
+brokers="111.198.10.15:20104"
dataTopic="cppTest"
-needSasl=0
-sasl.username="admin"
-sasl.password="casicss"
+statusTopic="dev-status"
+needSasl=1
+saslUsername="admin"
+saslPassword="casicss"
[client]
clientId="phase"
appKey="bd593bdd20943d2db8af217c3712a460"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp b/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
index 5163335..cd39a40 100644
--- a/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
+++ b/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
@@ -19,3 +19,23 @@
return jsonObj;
}
+
+QJsonObject PhaseDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ QJsonArray channelActiveArray;
+ for (int i = 0; i < channelActive.size(); i++)
+ {
+ channelActiveArray.append(channelActive.at(i));
+ }
+ dataObj.insert("channelActive", channelActiveArray);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0201");
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/PhaseCompAcq/protocol/dto/PhaseDataDto.h b/PhaseCompAcq/protocol/dto/PhaseDataDto.h
index 0317a83..3d34384 100644
--- a/PhaseCompAcq/protocol/dto/PhaseDataDto.h
+++ b/PhaseCompAcq/protocol/dto/PhaseDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class PhaseDataDto : public QObject
{
@@ -23,6 +24,7 @@
QList channelDataStr;
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
signals:
diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro
index fae9d10..38de4cb 100644
--- a/CounterAcq/CounterAcq.pro
+++ b/CounterAcq/CounterAcq.pro
@@ -4,8 +4,7 @@
CONFIG += c++11
-FORMS += \
- CounterWindow.ui \
+FORMS += CounterWindow.ui
include(common/common.pri)
include(protocol/protocol.pri)
diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp
index d129f24..6e54474 100644
--- a/CounterAcq/CounterDevice.cpp
+++ b/CounterAcq/CounterDevice.cpp
@@ -9,9 +9,9 @@
connect(&this->serialUtil, &QSerialPortUtil::dataRecieved,
this, &CounterDevice::dataReceivedHandler);
-// kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
-// kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
-// kafkaUtil.createProducer();
+ kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS);
+ kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC);
+ kafkaUtil.createProducer();
}
CounterDevice::~CounterDevice()
@@ -110,8 +110,8 @@
// 2. 各个通道的clock diff数据
for (int i = 1; i <= counterData->channelActiveArray.size(); i++)
{
-// if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
-// {
+ if (counterData->channelActiveArray.at(i-1).toUInt() == 1)
+ {
QString chFilename("%1_CH_%2.log");
chFilename = chFilename.arg(devCode);
if (i < 10)
@@ -131,11 +131,16 @@
QJsonObject jsonObj = counterData->toJSON(i - 1);
jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
jsonObj.insert("deviceId", deviceId);
-// kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
+ kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)));
}
-
- // 4. 在界面上简单显示相差数据结果
- emit this->sendDataToDraw(counterData);
-// }
+ }
}
-}
+
+ // 4. 在界面上简单显示相差数据结果
+ emit this->sendDataToDraw(counterData);
+
+ QJsonObject statusObj = counterData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
+ }
diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp
index 6e69dda..f760c3e 100644
--- a/CounterAcq/CounterWindow.cpp
+++ b/CounterAcq/CounterWindow.cpp
@@ -154,26 +154,6 @@
refChValue->setFont(labelFont);
vbox->addWidget(refChValue);
- QLabel * loadLabel = new QLabel();
- loadLabel->setText("负载");
- loadLabel->setFont(labelFont);
- loadLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(loadLabel);
- QLineEdit * loadValue = new QLineEdit();
- loadValue->setFixedWidth(60);
- loadValue->setFont(labelFont);
- vbox->addWidget(loadValue);
-
- QLabel * levelLabel = new QLabel();
- levelLabel->setText("触发电平");
- levelLabel->setFont(labelFont);
- levelLabel->setStyleSheet("margin-left:20;");
- vbox->addWidget(levelLabel);
- QLineEdit * levelValue = new QLineEdit();
- levelValue->setFixedWidth(60);
- levelValue->setFont(labelFont);
- vbox->addWidget(levelValue);
-
QLabel * validLabel = new QLabel();
validLabel->setText("-");
validLabel->setFont(labelFont);
@@ -202,7 +182,6 @@
}
// 1. 判断数据属于哪个设备,显示在不同的widget上
- qDebug() << counterData->toJSON() << counterData->devCode << "---" << counterData->frameId;
// 更新所有通道BOX的值
for (int i = 0; i < counterData->channelDataArray.size(); i++)
@@ -215,7 +194,7 @@
((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 s").arg(counterData->channelDataArray.at(i)));
((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId);
((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId));
- ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
+ ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效");
}
}
diff --git a/CounterAcq/CounterWindow.ui b/CounterAcq/CounterWindow.ui
index 9ac6eb3..40c8335 100644
--- a/CounterAcq/CounterWindow.ui
+++ b/CounterAcq/CounterWindow.ui
@@ -150,6 +150,25 @@
最小化
+
+
+
+ 680
+ 20
+ 61
+ 16
+
+
+
+
+ 微软雅黑
+ 10
+
+
+
+
+
+
diff --git a/CounterAcq/common/utils/QKafkaUtil.cpp b/CounterAcq/common/utils/QKafkaUtil.cpp
index b30cf45..231c02b 100644
--- a/CounterAcq/common/utils/QKafkaUtil.cpp
+++ b/CounterAcq/common/utils/QKafkaUtil.cpp
@@ -49,6 +49,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/CounterAcq/common/utils/QKafkaUtil.h b/CounterAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/CounterAcq/common/utils/QKafkaUtil.h
+++ b/CounterAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/CounterAcq/common/utils/QSerialPortUtil.cpp b/CounterAcq/common/utils/QSerialPortUtil.cpp
index bd62a00..491b8fa 100644
--- a/CounterAcq/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcq/common/utils/QSerialPortUtil.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -20,6 +21,23 @@
open = serial.open(QIODevice::ReadWrite);
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
+ {
+ // mock data received per second
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
+ }
+
if (open == true)
{
// 绑定信号与槽
diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/CounterAcq/common/utils/SettingConfig.cpp
+++ b/CounterAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/CounterAcq/common/utils/SettingConfig.h
+++ b/CounterAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini
index 7307187..bded175 100644
--- a/CounterAcq/conf/config.ini
+++ b/CounterAcq/conf/config.ini
@@ -2,16 +2,18 @@
baudRate=115200
[kafka]
-needKafka=0
-brokers="111.198.10.15:12502"
-dataTopic="cppTest"
-needSasl=0
+needKafka=1
+brokers="111.198.10.15:20104"
+dataTopic="clock-data"
+statusTopic="dev-status"
+needSasl=1
saslUsername="admin"
saslPassword="casicss"
[client]
clientId="clock"
appKey="bd347bdd20943d2db8af558c3712a357"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp
index 5d49032..e8c86c8 100644
--- a/CounterAcq/protocol/CounterProtocolXH.cpp
+++ b/CounterAcq/protocol/CounterProtocolXH.cpp
@@ -20,8 +20,11 @@
QStringList subList = contentStr.split(COUNTER_FRAME_CONTENT_SEP);
QString statusStr = subList.at(0);
+ QString refType = statusStr.mid(0, 1);
+ counterData->refType = refType;
+
QString channelStatus = statusStr.mid(1, COUNTER_MESSURE_CHANNEL);
- int channelRefNo = statusStr.mid(17, 2).toInt();
+ qint8 channelRefNo = statusStr.mid(17, 2).toInt();
counterData->channelRefId = channelRefNo;
for (int i = 0; i < COUNTER_MESSURE_CHANNEL; i++)
diff --git a/CounterAcq/protocol/dto/CounterDataDto.cpp b/CounterAcq/protocol/dto/CounterDataDto.cpp
index 711911f..1036361 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.cpp
+++ b/CounterAcq/protocol/dto/CounterDataDto.cpp
@@ -6,22 +6,6 @@
}
-QJsonObject CounterDataDto::toJSON()
-{
- QJsonObject jsonObj;
-
- QJsonObject dataObj;
- dataObj.insert("channelRefNo", this->channelRefId);
- dataObj.insert("dataValue", QString("%1").arg(this->channelClockValue * 1E-12));
- dataObj.insert("rawValue", QString("%1").arg(this->channelData));
- dataObj.insert("frameId", this->frameId);
-
- jsonObj.insert("channelNo", this->channelId);
- jsonObj.insert("ts", this->milisecond);
- jsonObj.insert("data", dataObj);
-
- return jsonObj;
-}
QJsonObject CounterDataDto::toJSON(int i)
{
@@ -40,18 +24,32 @@
return jsonObj;
}
+QJsonObject CounterDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ dataObj.insert("refType", this->refType);
+
+ QJsonArray channelActive;
+ for (int i = 0; i < channelActiveArray.size(); i++)
+ {
+ channelActive.append(channelActiveArray.at(i));
+ }
+ dataObj.insert("channelActive", channelActive);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("data", dataObj);
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0101");
+
+ return jsonObj;
+}
+
void CounterDataDto::clone(CounterDataDto *copy)
{
copy->frameId = this->frameId;
- copy->level = this->level;
- copy->load = this->load;
- copy->channelData = this->channelData;
copy->channelRefId = this->channelRefId;
- copy->channelActive = this->channelActive;
- copy->channelId = channelId;
- copy->type = 0;
-
- copy->channelClockValue = this->channelClockValue;
copy->rawFrame = this->rawFrame;
diff --git a/CounterAcq/protocol/dto/CounterDataDto.h b/CounterAcq/protocol/dto/CounterDataDto.h
index 60aaaae..0e5b7ea 100644
--- a/CounterAcq/protocol/dto/CounterDataDto.h
+++ b/CounterAcq/protocol/dto/CounterDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class CounterDataDto : public QObject
{
@@ -11,29 +12,22 @@
public:
explicit CounterDataDto(QObject *parent = nullptr);
- QString frameId; // 帧ID -- <8>
- double level; // 触发电平浮点数 -- <7>
- QString load; // 负载(0=50欧姆,1=1M欧姆) -- <6>
- qlonglong channelData; // 通道测量数据,单位:10ps -- <5>
qint8 channelRefId; // 参考通道号 -- <4>
- qint8 channelActive; // 通道有效标志 -- <3>
- qint8 channelId; // 测量通道号 -- <2>
- qint8 type = 0; // 测量状态 -- <1>
-
- double channelClockValue; //
+ QString refType;
QList channelActiveArray; // xhts
QList channelDataArray; // xhts
QByteArray rawFrame; // 原始帧字节数组
+ QString frameId; // 帧ID -- <8>
QString timestamp; // 时间戳字符串
qlonglong milisecond; // 毫秒计数
QString devCode;
QString devStatus;
- QJsonObject toJSON();
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
void clone(CounterDataDto * copy);
signals:
diff --git a/CounterAcqBM/common/utils/QSerialPortUtil.cpp b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
index aa8e2c4..c22b803 100644
--- a/CounterAcqBM/common/utils/QSerialPortUtil.cpp
+++ b/CounterAcqBM/common/utils/QSerialPortUtil.cpp
@@ -22,18 +22,18 @@
std::cout << QString("%1, %2, %3").arg(portName).arg(baudRate).arg(open).toStdString() << std::endl;
- if (open == true)
- {
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
+// if (open == true)
+// {
+// // 绑定信号与槽
+// connect(&serial, &QSerialPort::readyRead,
+// this, &QSerialPortUtil::readData);
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
- }
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+// }
}
void QSerialPortUtil::sendData(QByteArray data)
diff --git a/PhaseCompAcq/PhaseDevice.cpp b/PhaseCompAcq/PhaseDevice.cpp
index 547ed82..a13ba95 100644
--- a/PhaseCompAcq/PhaseDevice.cpp
+++ b/PhaseCompAcq/PhaseDevice.cpp
@@ -139,4 +139,9 @@
// 4. 在界面上简单显示相差数据结果
emit this->sendDataToDraw(phaseData);
+
+ QJsonObject statusObj = phaseData->toStatusJSON();
+ statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID);
+ statusObj.insert("deviceId", deviceId);
+ kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact)));
}
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.cpp b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
index 0cd1639..17f10c0 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.cpp
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.cpp
@@ -50,6 +50,11 @@
int QKafkaUtil::produceMessage(QString message)
{
+ return produceMessage(this->topic, message);
+}
+
+int QKafkaUtil::produceMessage(QString topic, QString message)
+{
auto retCode = producer->produce(topic.toStdString(), RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY,
const_cast(message.toStdString().c_str()), message.size(),
nullptr, 0, 0, nullptr, nullptr);
diff --git a/PhaseCompAcq/common/utils/QKafkaUtil.h b/PhaseCompAcq/common/utils/QKafkaUtil.h
index 289ea6f..de63820 100644
--- a/PhaseCompAcq/common/utils/QKafkaUtil.h
+++ b/PhaseCompAcq/common/utils/QKafkaUtil.h
@@ -16,6 +16,7 @@
int createProducer();
int produceMessage(QString message);
+ int produceMessage(QString topic, QString message);
private:
QString brokers;
diff --git a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
index 64da0f7..035040f 100644
--- a/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
+++ b/PhaseCompAcq/common/utils/QSerialPortUtil.cpp
@@ -4,6 +4,7 @@
#include
#include
#include "common/utils/QByteUtil.h"
+#include "common/utils/SettingConfig.h"
QSerialPortUtil::QSerialPortUtil(QObject *parent) : QObject(parent)
{
@@ -21,17 +22,21 @@
open = serial.open(QIODevice::ReadWrite);
- if (open == true)
+ if (SettingConfig::getInstance().WORK_TYPE == "mock")
{
- // 绑定信号与槽
- connect(&serial, &QSerialPort::readyRead,
- this, &QSerialPortUtil::readData);
-
// mock data received per second
-// QTimer * timer = new QTimer(this);
-// connect(timer, &QTimer::timeout,
-// this, &QSerialPortUtil::mockReceivData);
-// timer->start(1000);
+ QTimer * timer = new QTimer(this);
+ connect(timer, &QTimer::timeout,
+ this, &QSerialPortUtil::mockReceivData);
+ timer->start(1000);
+ } else
+ {
+ if (open == true)
+ {
+ // 绑定信号与槽
+ connect(&serial, &QSerialPort::readyRead,
+ this, &QSerialPortUtil::readData);
+ }
}
}
diff --git a/PhaseCompAcq/common/utils/SettingConfig.cpp b/PhaseCompAcq/common/utils/SettingConfig.cpp
index 9a84a43..da8a3df 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.cpp
+++ b/PhaseCompAcq/common/utils/SettingConfig.cpp
@@ -10,12 +10,14 @@
NEED_KAFKA = getProperty("kafka", "needKafka").toInt();
KAFKA_BROKERS = getProperty("kafka", "brokers").toString();
KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString();
+ KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString();
NEED_SASL = getProperty("kafka", "needSasl").toInt();
SASL_USERNAME = getProperty("kafka", "saslUsername").toString();
SASL_PASSWORD = getProperty("kafka", "saslPassword").toString();
CLIENT_ID = getProperty("client", "clientId").toString();
APP_KEY = getProperty("client", "appKey").toString();
+ WORK_TYPE = getProperty("client", "workMode").toString();
BASE_URL = getProperty("http", "baseUrl").toString();
diff --git a/PhaseCompAcq/common/utils/SettingConfig.h b/PhaseCompAcq/common/utils/SettingConfig.h
index 0038ecc..fe8d070 100644
--- a/PhaseCompAcq/common/utils/SettingConfig.h
+++ b/PhaseCompAcq/common/utils/SettingConfig.h
@@ -32,12 +32,14 @@
int NEED_KAFKA;
QString KAFKA_BROKERS;
QString KAFKA_DATA_TOPIC;
+ QString KAFKA_STATUS_TOPIC;
int NEED_SASL;
QString SASL_USERNAME;
QString SASL_PASSWORD;
QString CLIENT_ID;
QString APP_KEY;
+ QString WORK_TYPE;
QString BASE_URL;
diff --git a/PhaseCompAcq/conf/config.ini b/PhaseCompAcq/conf/config.ini
index 46d97d7..a65af8b 100644
--- a/PhaseCompAcq/conf/config.ini
+++ b/PhaseCompAcq/conf/config.ini
@@ -3,15 +3,17 @@
[kafka]
needKafka=1
-brokers="111.198.10.15:12502"
+brokers="111.198.10.15:20104"
dataTopic="cppTest"
-needSasl=0
-sasl.username="admin"
-sasl.password="casicss"
+statusTopic="dev-status"
+needSasl=1
+saslUsername="admin"
+saslPassword="casicss"
[client]
clientId="phase"
appKey="bd593bdd20943d2db8af217c3712a460"
+workMode="mock"
[http]
baseUrl="http://111.198.10.15:11410"
diff --git a/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp b/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
index 5163335..cd39a40 100644
--- a/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
+++ b/PhaseCompAcq/protocol/dto/PhaseDataDto.cpp
@@ -19,3 +19,23 @@
return jsonObj;
}
+
+QJsonObject PhaseDataDto::toStatusJSON()
+{
+ QJsonObject jsonObj;
+
+ QJsonObject dataObj;
+ QJsonArray channelActiveArray;
+ for (int i = 0; i < channelActive.size(); i++)
+ {
+ channelActiveArray.append(channelActive.at(i));
+ }
+ dataObj.insert("channelActive", channelActiveArray);
+ dataObj.insert("devStatus", "1");
+
+ jsonObj.insert("ts", this->milisecond);
+ jsonObj.insert("frameType", "0201");
+ jsonObj.insert("data", dataObj);
+
+ return jsonObj;
+}
diff --git a/PhaseCompAcq/protocol/dto/PhaseDataDto.h b/PhaseCompAcq/protocol/dto/PhaseDataDto.h
index 0317a83..3d34384 100644
--- a/PhaseCompAcq/protocol/dto/PhaseDataDto.h
+++ b/PhaseCompAcq/protocol/dto/PhaseDataDto.h
@@ -4,6 +4,7 @@
#include
#include
#include
+#include
class PhaseDataDto : public QObject
{
@@ -23,6 +24,7 @@
QList channelDataStr;
QJsonObject toJSON(int i);
+ QJsonObject toStatusJSON();
signals:
diff --git a/ZXSSCJ.pro b/ZXSSCJ.pro
index 5eccd3a..04b410c 100644
--- a/ZXSSCJ.pro
+++ b/ZXSSCJ.pro
@@ -3,9 +3,9 @@
#定义了ordered表示子项目按照添加的顺序来编译
#CONFIG += ordered
-#SUBDIRS += CounterAcq #计数器数据采集
+SUBDIRS += CounterAcq #计数器数据采集
#SUBDIRS += CounterAcqBM #6906计数器数据采集
-#SUBDIRS += PhaseCompAcq #比相仪数据采集
+SUBDIRS += PhaseCompAcq #比相仪数据采集
#SUBDIRS += DevStatusAcq
-SUBDIRS += DeviceHub #
+#SUBDIRS += DeviceHub #
#SUBDIRS += HClockAcq #氢钟状态数据采集