diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index 4b69272..06cfddd 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,10 +1,10 @@ #include "DeviceBase.h" -#include "FrequencyTuning.h" -#include "SignalGenerator.h" -#include "TimeSwitcher.h" -#include "FreqSwitcher.h" -#include "BCodeTerminal.h" -#include "TimeReplicator.h" +//#include "FrequencyTuning.h" +//#include "SignalGenerator.h" +//#include "TimeSwitcher.h" +//#include "FreqSwitcher.h" +//#include "BCodeTerminal.h" +//#include "TimeReplicator.h" #include "FreqReplicator.h" #include @@ -42,25 +42,26 @@ DeviceBase * DeviceBase::deviceFactory(QString deviceType, QObject * parent) { DeviceBase * base = 0; - if (deviceType == "03") - { - base = new FrequencyTuning(parent); - } else if (deviceType == "04") - { - base = new SignalGenerator(parent); - } else if (deviceType == "05") - { - base = new TimeSwitcher(parent); - } else if (deviceType == "06") - { - base = new FreqSwitcher(parent); - } else if (deviceType == "07") - { - base = new BCodeTerminal(parent); - } else if (deviceType == "09") - { - base = new TimeReplicator(parent); - } else if (deviceType == "10") +// if (deviceType == "03") +// { +// base = new FrequencyTuning(parent); +// } else if (deviceType == "04") +// { +// base = new SignalGenerator(parent); +// } else if (deviceType == "05") +// { +// base = new TimeSwitcher(parent); +// } else if (deviceType == "06") +// { +// base = new FreqSwitcher(parent); +// } else if (deviceType == "07") +// { +// base = new BCodeTerminal(parent); +// } else if (deviceType == "09") +// { +// base = new TimeReplicator(parent); +// } else + if (deviceType == "10") { base = new FreqReplicator(parent); } diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index 4b69272..06cfddd 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,10 +1,10 @@ #include "DeviceBase.h" -#include "FrequencyTuning.h" -#include "SignalGenerator.h" -#include "TimeSwitcher.h" -#include "FreqSwitcher.h" -#include "BCodeTerminal.h" -#include "TimeReplicator.h" +//#include "FrequencyTuning.h" +//#include "SignalGenerator.h" +//#include "TimeSwitcher.h" +//#include "FreqSwitcher.h" +//#include "BCodeTerminal.h" +//#include "TimeReplicator.h" #include "FreqReplicator.h" #include @@ -42,25 +42,26 @@ DeviceBase * DeviceBase::deviceFactory(QString deviceType, QObject * parent) { DeviceBase * base = 0; - if (deviceType == "03") - { - base = new FrequencyTuning(parent); - } else if (deviceType == "04") - { - base = new SignalGenerator(parent); - } else if (deviceType == "05") - { - base = new TimeSwitcher(parent); - } else if (deviceType == "06") - { - base = new FreqSwitcher(parent); - } else if (deviceType == "07") - { - base = new BCodeTerminal(parent); - } else if (deviceType == "09") - { - base = new TimeReplicator(parent); - } else if (deviceType == "10") +// if (deviceType == "03") +// { +// base = new FrequencyTuning(parent); +// } else if (deviceType == "04") +// { +// base = new SignalGenerator(parent); +// } else if (deviceType == "05") +// { +// base = new TimeSwitcher(parent); +// } else if (deviceType == "06") +// { +// base = new FreqSwitcher(parent); +// } else if (deviceType == "07") +// { +// base = new BCodeTerminal(parent); +// } else if (deviceType == "09") +// { +// base = new TimeReplicator(parent); +// } else + if (deviceType == "10") { base = new FreqReplicator(parent); } diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8a3b271..e06bee3 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaProducer.h" +//#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -43,7 +43,7 @@ QString devType; QSerialPortUtil serialUtil; - QKafkaProducer kafkaProducer; +// QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index 4b69272..06cfddd 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,10 +1,10 @@ #include "DeviceBase.h" -#include "FrequencyTuning.h" -#include "SignalGenerator.h" -#include "TimeSwitcher.h" -#include "FreqSwitcher.h" -#include "BCodeTerminal.h" -#include "TimeReplicator.h" +//#include "FrequencyTuning.h" +//#include "SignalGenerator.h" +//#include "TimeSwitcher.h" +//#include "FreqSwitcher.h" +//#include "BCodeTerminal.h" +//#include "TimeReplicator.h" #include "FreqReplicator.h" #include @@ -42,25 +42,26 @@ DeviceBase * DeviceBase::deviceFactory(QString deviceType, QObject * parent) { DeviceBase * base = 0; - if (deviceType == "03") - { - base = new FrequencyTuning(parent); - } else if (deviceType == "04") - { - base = new SignalGenerator(parent); - } else if (deviceType == "05") - { - base = new TimeSwitcher(parent); - } else if (deviceType == "06") - { - base = new FreqSwitcher(parent); - } else if (deviceType == "07") - { - base = new BCodeTerminal(parent); - } else if (deviceType == "09") - { - base = new TimeReplicator(parent); - } else if (deviceType == "10") +// if (deviceType == "03") +// { +// base = new FrequencyTuning(parent); +// } else if (deviceType == "04") +// { +// base = new SignalGenerator(parent); +// } else if (deviceType == "05") +// { +// base = new TimeSwitcher(parent); +// } else if (deviceType == "06") +// { +// base = new FreqSwitcher(parent); +// } else if (deviceType == "07") +// { +// base = new BCodeTerminal(parent); +// } else if (deviceType == "09") +// { +// base = new TimeReplicator(parent); +// } else + if (deviceType == "10") { base = new FreqReplicator(parent); } diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8a3b271..e06bee3 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaProducer.h" +//#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -43,7 +43,7 @@ QString devType; QSerialPortUtil serialUtil; - QKafkaProducer kafkaProducer; +// QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index 8767f90..ea50664 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -12,9 +12,9 @@ connect(this, &FreqReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqRepForm, &FreqReplicatorForm::drawDeviceFrameOnForm); - kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaProducer.createProducer(); +// kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); +// kafkaProducer.createProducer(); this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } @@ -29,7 +29,7 @@ { QByteArray buffer; - // freq replicator + // 频率信号放大器 buffer = QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"); buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8")); @@ -40,12 +40,11 @@ { this->dataBuff.append(data); - std::cout << QByteUtil::binToHexString(dataBuff).toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -81,7 +80,6 @@ void FreqReplicator::afterFramePhase(DeviceFrameBaseDto * frameDto) { - std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << QByteUtil::binToHexString(frameDto->rawFrame).toStdString() << std::endl; // 0. 输出到日志文件中 @@ -103,7 +101,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); +// kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index 4b69272..06cfddd 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,10 +1,10 @@ #include "DeviceBase.h" -#include "FrequencyTuning.h" -#include "SignalGenerator.h" -#include "TimeSwitcher.h" -#include "FreqSwitcher.h" -#include "BCodeTerminal.h" -#include "TimeReplicator.h" +//#include "FrequencyTuning.h" +//#include "SignalGenerator.h" +//#include "TimeSwitcher.h" +//#include "FreqSwitcher.h" +//#include "BCodeTerminal.h" +//#include "TimeReplicator.h" #include "FreqReplicator.h" #include @@ -42,25 +42,26 @@ DeviceBase * DeviceBase::deviceFactory(QString deviceType, QObject * parent) { DeviceBase * base = 0; - if (deviceType == "03") - { - base = new FrequencyTuning(parent); - } else if (deviceType == "04") - { - base = new SignalGenerator(parent); - } else if (deviceType == "05") - { - base = new TimeSwitcher(parent); - } else if (deviceType == "06") - { - base = new FreqSwitcher(parent); - } else if (deviceType == "07") - { - base = new BCodeTerminal(parent); - } else if (deviceType == "09") - { - base = new TimeReplicator(parent); - } else if (deviceType == "10") +// if (deviceType == "03") +// { +// base = new FrequencyTuning(parent); +// } else if (deviceType == "04") +// { +// base = new SignalGenerator(parent); +// } else if (deviceType == "05") +// { +// base = new TimeSwitcher(parent); +// } else if (deviceType == "06") +// { +// base = new FreqSwitcher(parent); +// } else if (deviceType == "07") +// { +// base = new BCodeTerminal(parent); +// } else if (deviceType == "09") +// { +// base = new TimeReplicator(parent); +// } else + if (deviceType == "10") { base = new FreqReplicator(parent); } diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8a3b271..e06bee3 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaProducer.h" +//#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -43,7 +43,7 @@ QString devType; QSerialPortUtil serialUtil; - QKafkaProducer kafkaProducer; +// QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index 8767f90..ea50664 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -12,9 +12,9 @@ connect(this, &FreqReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqRepForm, &FreqReplicatorForm::drawDeviceFrameOnForm); - kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaProducer.createProducer(); +// kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); +// kafkaProducer.createProducer(); this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } @@ -29,7 +29,7 @@ { QByteArray buffer; - // freq replicator + // 频率信号放大器 buffer = QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"); buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8")); @@ -40,12 +40,11 @@ { this->dataBuff.append(data); - std::cout << QByteUtil::binToHexString(dataBuff).toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -81,7 +80,6 @@ void FreqReplicator::afterFramePhase(DeviceFrameBaseDto * frameDto) { - std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << QByteUtil::binToHexString(frameDto->rawFrame).toStdString() << std::endl; // 0. 输出到日志文件中 @@ -103,7 +101,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); +// kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 18bc01f..5702c28 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -1,4 +1,4 @@ -#ifndef FREQREPLICATOR_H +#ifndef FREQREPLICATOR_H #define FREQREPLICATOR_H #include @@ -16,15 +16,12 @@ void mockReceivData(); void afterFramePhase(DeviceFrameBaseDto * frameDto); -// void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); -// void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); -// void commandReceivedHandler(QJsonObject command); }; #endif // FREQREPLICATOR_H diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index 4b69272..06cfddd 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,10 +1,10 @@ #include "DeviceBase.h" -#include "FrequencyTuning.h" -#include "SignalGenerator.h" -#include "TimeSwitcher.h" -#include "FreqSwitcher.h" -#include "BCodeTerminal.h" -#include "TimeReplicator.h" +//#include "FrequencyTuning.h" +//#include "SignalGenerator.h" +//#include "TimeSwitcher.h" +//#include "FreqSwitcher.h" +//#include "BCodeTerminal.h" +//#include "TimeReplicator.h" #include "FreqReplicator.h" #include @@ -42,25 +42,26 @@ DeviceBase * DeviceBase::deviceFactory(QString deviceType, QObject * parent) { DeviceBase * base = 0; - if (deviceType == "03") - { - base = new FrequencyTuning(parent); - } else if (deviceType == "04") - { - base = new SignalGenerator(parent); - } else if (deviceType == "05") - { - base = new TimeSwitcher(parent); - } else if (deviceType == "06") - { - base = new FreqSwitcher(parent); - } else if (deviceType == "07") - { - base = new BCodeTerminal(parent); - } else if (deviceType == "09") - { - base = new TimeReplicator(parent); - } else if (deviceType == "10") +// if (deviceType == "03") +// { +// base = new FrequencyTuning(parent); +// } else if (deviceType == "04") +// { +// base = new SignalGenerator(parent); +// } else if (deviceType == "05") +// { +// base = new TimeSwitcher(parent); +// } else if (deviceType == "06") +// { +// base = new FreqSwitcher(parent); +// } else if (deviceType == "07") +// { +// base = new BCodeTerminal(parent); +// } else if (deviceType == "09") +// { +// base = new TimeReplicator(parent); +// } else + if (deviceType == "10") { base = new FreqReplicator(parent); } diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8a3b271..e06bee3 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaProducer.h" +//#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -43,7 +43,7 @@ QString devType; QSerialPortUtil serialUtil; - QKafkaProducer kafkaProducer; +// QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index 8767f90..ea50664 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -12,9 +12,9 @@ connect(this, &FreqReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqRepForm, &FreqReplicatorForm::drawDeviceFrameOnForm); - kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaProducer.createProducer(); +// kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); +// kafkaProducer.createProducer(); this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } @@ -29,7 +29,7 @@ { QByteArray buffer; - // freq replicator + // 频率信号放大器 buffer = QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"); buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8")); @@ -40,12 +40,11 @@ { this->dataBuff.append(data); - std::cout << QByteUtil::binToHexString(dataBuff).toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -81,7 +80,6 @@ void FreqReplicator::afterFramePhase(DeviceFrameBaseDto * frameDto) { - std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << QByteUtil::binToHexString(frameDto->rawFrame).toStdString() << std::endl; // 0. 输出到日志文件中 @@ -103,7 +101,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); +// kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 18bc01f..5702c28 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -1,4 +1,4 @@ -#ifndef FREQREPLICATOR_H +#ifndef FREQREPLICATOR_H #define FREQREPLICATOR_H #include @@ -16,15 +16,12 @@ void mockReceivData(); void afterFramePhase(DeviceFrameBaseDto * frameDto); -// void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); -// void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); -// void commandReceivedHandler(QJsonObject command); }; #endif // FREQREPLICATOR_H diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index fedab85..06e82c0 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/SignalGenerator.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FrequencyTuning.h +#HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/SignalGenerator.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FrequencyTuning.cpp +#SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 46c14df..d129f24 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -9,9 +9,6 @@ connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - connect(this, &CounterDevice::successDataCalculate, - this, &CounterDevice::afterFramePhase); - // kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); // kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); // kafkaUtil.createProducer(); @@ -81,7 +78,6 @@ { // 1. 清空dataBuff,等待下一帧的数据 // this->dataBuff.clear(); - std::cout << "+++" << frameByte.toStdString() << std::endl; // 2. 补充其他字段 QDateTime now = QDateTime::currentDateTime(); @@ -90,9 +86,6 @@ counterData->devCode = devCode; this->afterFramePhase(counterData); - - // 3 计算数据ID一样的测量数据的时差值,通道值-参考通道值 - // this->pushChannelRawFrame(counterData); } // 在此处释放内存,不影响后续显示 @@ -103,19 +96,6 @@ } } -void CounterDevice::dataReceivedHandlerByUDP() -{ - - QByteArray ba; - while(udpClient->hasPendingDatagrams()) - { - ba.resize(udpClient->pendingDatagramSize()); - udpClient->readDatagram(ba.data(), ba.size()); - std::cout << ba.data() << std::endl; - } - - dataReceivedHandler(ba); -} void CounterDevice::afterFramePhase(CounterDataDto * counterData) { @@ -130,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) @@ -156,60 +136,6 @@ // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); - } - } -} - -void CounterDevice::pushChannelRawFrame(CounterDataDto * counterData) -{ - QString currentFrameId = counterData->frameId; - QString currentChannelId = QString("%1").arg(counterData->channelId); - - if (counterData->channelId == counterData->channelRefId) - { - // 自身是参考通道 - bench.insert(currentFrameId, counterData->channelData); - counterData->channelClockValue = 0; - - emit successDataCalculate(counterData); - - qlonglong thisBench = counterData->channelData; - // 遍历temp,处理之前的临时暂存的队列 - if (hisList.isEmpty() == false) - { - for (int i = 0; i < hisList.size(); i++) - { - CounterDataDto * hisItem = hisList.at(i); - if (hisItem->frameId == currentFrameId) - { - hisItem->channelClockValue = (hisItem->channelData - thisBench) * 10; - - emit successDataCalculate(hisItem); - delete hisItem; - } - } - - hisList.clear(); - } - } else - { - // 自身不是参考通道,减去相同frameId的参考通道值 - if (bench.contains(currentFrameId) == true) - { - // 在参考基准中能找到 - qlonglong currentBench = bench.find(currentFrameId).value(); - counterData->channelClockValue = (counterData->channelData - currentBench) * 10; // 10ps - - emit successDataCalculate(counterData); - } else - { - // 暂存,等收到基准之后再处置 - CounterDataDto * copyPoint = new CounterDataDto(); - - // ★clone一份对象,存入缓存队列 - counterData->clone(copyPoint); - - hisList.append(copyPoint); - } +// } } } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index 3776042..7777c4d 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -37,21 +37,18 @@ QSerialPortUtil serialUtil; // QKafkaUtil kafkaUtil; QByteArray dataBuff; - QUdpSocket * udpClient; QMap bench; QList hisList; - void pushChannelRawFrame(CounterDataDto * counterData); + void afterFramePhase(CounterDataDto * counterData); signals: void sendDataToDraw(CounterDataDto * counterData); - void successDataCalculate(CounterDataDto * counterData); public slots: void dataReceivedHandler(QByteArray data); - void dataReceivedHandlerByUDP(); - void afterFramePhase(CounterDataDto * counterData); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 63262dc..6e69dda 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -217,19 +217,6 @@ ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); } - /* - // 获取对应的通道BOX - QGroupBox * channelBox = (QGroupBox *)ui->scrollContents->children().at(counterData->channelId); - - // 赋值,对应的lineEdit/label - ((QLineEdit *)channelBox->children().at(2))->setText(counterData->timestamp); - ((QLineEdit *)channelBox->children().at(4))->setText(QString("%1 ps").arg(counterData->channelClockValue)); - ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); - ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); - ((QLineEdit *)channelBox->children().at(10))->setText(QString("%1 Ω").arg(counterData->load == 1 ? "1M" : "50")); - ((QLineEdit *)channelBox->children().at(12))->setText(QString("%1 V").arg(counterData->level)); - ((QLabel *)channelBox->children().at(13))->setText(counterData->channelActive == 1 ? "有效" : "无效"); - */ } int CounterWindow::initHttpToken() diff --git a/CounterAcq/protocol/CounterProtocolXH.cpp b/CounterAcq/protocol/CounterProtocolXH.cpp index 6ba3e50..fe2554f 100644 --- a/CounterAcq/protocol/CounterProtocolXH.cpp +++ b/CounterAcq/protocol/CounterProtocolXH.cpp @@ -64,7 +64,6 @@ { if (rawData.at(i + 1) == '\n') { - ba.append("\r\n"); resultList.append(ba); ba.clear(); i++; diff --git a/DeviceHub/DeviceHubWindow.cpp b/DeviceHub/DeviceHubWindow.cpp index 9060246..14292ec 100644 --- a/DeviceHub/DeviceHubWindow.cpp +++ b/DeviceHub/DeviceHubWindow.cpp @@ -28,37 +28,19 @@ // 设置stackWidget的大小 ui->stackedWidget->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); - // add forms - freqTunForm = new FrequencyTuningForm(this); - ui->stackedWidget->addWidget(freqTunForm); - - signGenForm = new SignalGeneratorForm(this); - ui->stackedWidget->addWidget(signGenForm); - - tmSwitForm = new TimeSwitcherForm(this); - ui->stackedWidget->addWidget(tmSwitForm); - - freqSwitForm = new FreqSwitcherForm(this); - ui->stackedWidget->addWidget(freqSwitForm); - - bCodeTermForm = new BCodeTerminalForm(this); - ui->stackedWidget->addWidget(bCodeTermForm); - - keyTmSynchForm = new KeyTimeSynchForm(this); - ui->stackedWidget->addWidget(keyTmSynchForm); - - timeRepForm = new TimeReplicatorForm(this); - ui->stackedWidget->addWidget(timeRepForm); - - freqRepForm = new FreqReplicatorForm(this); - ui->stackedWidget->addWidget(freqRepForm); + // 添加设备状态Form + QStringList devTypes = SettingConfig::getInstance().DEV_TYPES.split(","); + for (int i = 0; i < devTypes.size(); i++) + { + this->initDeviceForm(devTypes.at(i)); + } // kafka consumer - kafkaConsumer = new QKafkaConsumer(this); - kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); - kafkaConsumer->createConsumer(); - kafkaConsumer->start(); +// kafkaConsumer = new QKafkaConsumer(this); +// kafkaConsumer->setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaConsumer->setTopic(SettingConfig::getInstance().KAFKA_CMD_TOPIC); +// kafkaConsumer->createConsumer(); +// kafkaConsumer->start(); // init device type and device list httpReq = new HttpRequestController(this); @@ -142,12 +124,14 @@ ConstCache::getInstance().deviceTypes.clear(); QJsonArray typeArray = response.find("data")->toArray(); - for (int i = 3; i < typeArray.size(); i++) + for (int i = 0; i < typeArray.size(); i++) { QJsonObject typeItem = typeArray.at(i).toObject(); - ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); - - ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + if (SettingConfig::getInstance().DEV_TYPES.contains(typeItem.find("value")->toString()) == true) + { + ui->devTypeSelect->addItem(typeItem.find("name")->toString(), typeItem.find("value")->toString()); + ConstCache::getInstance().deviceTypes.insert(typeItem.find("value")->toString(), typeItem.find("name")->toString()); + } } } @@ -159,7 +143,7 @@ item->setSizeHint({ 0, 30 }); } - // + // 默认选中第一个设备类型 ui->devTypeSelect->setCurrentIndex(model->rowCount() - 1); return response.find("code")->toInt(); @@ -185,7 +169,6 @@ qDebug() << item; DeviceBase * devicePtr = DeviceBase::deviceFactory(devType, this); - std::cout << typeid (devicePtr).name() << std::endl; if (devicePtr != 0) { devicePtr->setDevCode(item.find("deviceNo")->toString()); @@ -195,7 +178,11 @@ singleTypeDevList.append(devicePtr); - devicePtr->initSerialPort(); + // 如果是真实工作模式则打开串口连接 + if (SettingConfig::getInstance().WORK_MODE == "real") + { + devicePtr->initSerialPort(); + } } } this->allTypeDevList.insert(devType, singleTypeDevList); @@ -206,3 +193,54 @@ ui->devTypeSelect->setCurrentIndex(0); } + +void DeviceHubWindow::initDeviceForm(QString devType) +{ + if (devType == "03") + { + freqTunForm = new FrequencyTuningForm(this); + ui->stackedWidget->addWidget(freqTunForm); + } + + if (devType == "04") + { + signGenForm = new SignalGeneratorForm(this); + ui->stackedWidget->addWidget(signGenForm); + } + + if (devType == "05") + { + tmSwitForm = new TimeSwitcherForm(this); + ui->stackedWidget->addWidget(tmSwitForm); + } + + if (devType == "06") + { + freqSwitForm = new FreqSwitcherForm(this); + ui->stackedWidget->addWidget(freqSwitForm); + } + + if (devType == "07") + { + bCodeTermForm = new BCodeTerminalForm(this); + ui->stackedWidget->addWidget(bCodeTermForm); + } + + if (devType == "08") + { + keyTmSynchForm = new KeyTimeSynchForm(this); + ui->stackedWidget->addWidget(keyTmSynchForm); + } + + if (devType == "09") + { + timeRepForm = new TimeReplicatorForm(this); + ui->stackedWidget->addWidget(timeRepForm); + } + + if (devType == "10") + { + freqRepForm = new FreqReplicatorForm(this); + ui->stackedWidget->addWidget(freqRepForm); + } +} diff --git a/DeviceHub/DeviceHubWindow.h b/DeviceHub/DeviceHubWindow.h index 3dbc8d6..62b4055 100644 --- a/DeviceHub/DeviceHubWindow.h +++ b/DeviceHub/DeviceHubWindow.h @@ -5,7 +5,7 @@ #include #include "common/HttpRequestController.h" -#include "common/utils/QKafkaConsumer.h" +//#include "common/utils/QKafkaConsumer.h" #include "device/DeviceBase.h" #include "FrequencyTuningForm.h" #include "SignalGeneratorForm.h" @@ -32,7 +32,7 @@ int currentDevIndex; QMap> allTypeDevList; - QKafkaConsumer * kafkaConsumer; +// QKafkaConsumer * kafkaConsumer; QComboBox * getDevTypeSelect(); QComboBox * getDevSelect(); @@ -63,5 +63,6 @@ int initHttpToken(); int initDictDeviceTypes(); void initAllDeviceList(); + void initDeviceForm(QString devType); }; #endif // DEVICEHUBWINDOW_H diff --git a/DeviceHub/FreqReplicatorForm.cpp b/DeviceHub/FreqReplicatorForm.cpp index 32d6fac..e52ab24 100644 --- a/DeviceHub/FreqReplicatorForm.cpp +++ b/DeviceHub/FreqReplicatorForm.cpp @@ -1,4 +1,4 @@ -#include "FreqReplicatorForm.h" +#include "FreqReplicatorForm.h" #include "ui_FreqReplicatorForm.h" #include "DeviceHubWindow.h" @@ -19,7 +19,12 @@ // 获取设备对象 int devIndex = ((DeviceHubWindow *) this->parent()->parent())->currentDevIndex; FreqReplicator * device = (FreqReplicator *) ((DeviceHubWindow *) this->parent()->parent())->allTypeDevList.value("10").at(devIndex); - device->mockReceivData(); + + // mock测试工作模式则产生一条mock数据 + if (SettingConfig::getInstance().WORK_MODE == "mock") + { + device->mockReceivData(); + } } void FreqReplicatorForm::drawDeviceFrameOnForm(DeviceFrameBaseDto * frameData) @@ -29,6 +34,7 @@ { FreqReplicatorStatusDto * statusFrameDto = (FreqReplicatorStatusDto *) frameData; ui->frABCDStatus->setText(statusFrameDto->abOrCd); + ui->label_ts->setText(statusFrameDto->timestamp); QJsonObject dataObj = statusFrameDto->toJSON().find("data")->toObject(); QJsonDocument doc; diff --git a/DeviceHub/FreqReplicatorForm.ui b/DeviceHub/FreqReplicatorForm.ui index 54c86d4..cbc4ffb 100644 --- a/DeviceHub/FreqReplicatorForm.ui +++ b/DeviceHub/FreqReplicatorForm.ui @@ -151,6 +151,25 @@ 输入状态 + + + + 130 + 80 + 300 + 30 + + + + + 微软雅黑 + 12 + + + + + + diff --git a/DeviceHub/common/common.pri b/DeviceHub/common/common.pri index 86259e8..feeba36 100644 --- a/DeviceHub/common/common.pri +++ b/DeviceHub/common/common.pri @@ -3,8 +3,8 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaConsumer.cpp -SOURCES += $$PWD/utils/QKafkaProducer.cpp +#SOURCES += $$PWD/utils/QKafkaConsumer.cpp +#SOURCES += $$PWD/utils/QKafkaProducer.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,8 +13,8 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaConsumer.h -HEADERS += $$PWD/utils/QKafkaProducer.h +#HEADERS += $$PWD/utils/QKafkaConsumer.h +#HEADERS += $$PWD/utils/QKafkaProducer.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/DeviceHub/common/utils/SettingConfig.cpp b/DeviceHub/common/utils/SettingConfig.cpp index eeed12e..6f17295 100644 --- a/DeviceHub/common/utils/SettingConfig.cpp +++ b/DeviceHub/common/utils/SettingConfig.cpp @@ -17,6 +17,8 @@ CLIENT_ID = getProperty("client", "clientId").toString(); APP_KEY = getProperty("client", "appKey").toString(); + DEV_TYPES = getProperty("client", "devTypes").toString(); + WORK_MODE = getProperty("client", "workMode").toString(); BASE_URL = getProperty("http", "baseUrl").toString(); diff --git a/DeviceHub/common/utils/SettingConfig.h b/DeviceHub/common/utils/SettingConfig.h index 2f0c31f..c50bcc0 100644 --- a/DeviceHub/common/utils/SettingConfig.h +++ b/DeviceHub/common/utils/SettingConfig.h @@ -39,6 +39,8 @@ QString CLIENT_ID; QString APP_KEY; + QString DEV_TYPES; + QString WORK_MODE; QString BASE_URL; diff --git a/DeviceHub/conf/config.ini b/DeviceHub/conf/config.ini index e26b49f..64e57ba 100644 --- a/DeviceHub/conf/config.ini +++ b/DeviceHub/conf/config.ini @@ -3,14 +3,19 @@ [kafka] needKafka=1 -brokers="111.198.10.15:12502" -dataTopic="cppTest" -cmdTopic="cppTest" -cmdcbTopic="cppTest" +brokers="111.198.10.15:20104" +dataTopic="dev-status" +cmdTopic="dev-command" +cmdcbTopic="dev-command-cb" +needSasl=1 +saslUsername="admin" +saslPassword="casicss" [client] -clientId="dev-status" -appKey="bd593bdd20943d2db8af217c3712a460" +clientId="deviceStatus" +appKey="bd347bdd57415d2db8af432c3712a177" +devTypes="09,10" +workMode="mock" [http] baseUrl="http://111.198.10.15:11410" diff --git a/DeviceHub/device/DeviceBase.cpp b/DeviceHub/device/DeviceBase.cpp index 4b69272..06cfddd 100644 --- a/DeviceHub/device/DeviceBase.cpp +++ b/DeviceHub/device/DeviceBase.cpp @@ -1,10 +1,10 @@ #include "DeviceBase.h" -#include "FrequencyTuning.h" -#include "SignalGenerator.h" -#include "TimeSwitcher.h" -#include "FreqSwitcher.h" -#include "BCodeTerminal.h" -#include "TimeReplicator.h" +//#include "FrequencyTuning.h" +//#include "SignalGenerator.h" +//#include "TimeSwitcher.h" +//#include "FreqSwitcher.h" +//#include "BCodeTerminal.h" +//#include "TimeReplicator.h" #include "FreqReplicator.h" #include @@ -42,25 +42,26 @@ DeviceBase * DeviceBase::deviceFactory(QString deviceType, QObject * parent) { DeviceBase * base = 0; - if (deviceType == "03") - { - base = new FrequencyTuning(parent); - } else if (deviceType == "04") - { - base = new SignalGenerator(parent); - } else if (deviceType == "05") - { - base = new TimeSwitcher(parent); - } else if (deviceType == "06") - { - base = new FreqSwitcher(parent); - } else if (deviceType == "07") - { - base = new BCodeTerminal(parent); - } else if (deviceType == "09") - { - base = new TimeReplicator(parent); - } else if (deviceType == "10") +// if (deviceType == "03") +// { +// base = new FrequencyTuning(parent); +// } else if (deviceType == "04") +// { +// base = new SignalGenerator(parent); +// } else if (deviceType == "05") +// { +// base = new TimeSwitcher(parent); +// } else if (deviceType == "06") +// { +// base = new FreqSwitcher(parent); +// } else if (deviceType == "07") +// { +// base = new BCodeTerminal(parent); +// } else if (deviceType == "09") +// { +// base = new TimeReplicator(parent); +// } else + if (deviceType == "10") { base = new FreqReplicator(parent); } diff --git a/DeviceHub/device/DeviceBase.h b/DeviceHub/device/DeviceBase.h index 8a3b271..e06bee3 100644 --- a/DeviceHub/device/DeviceBase.h +++ b/DeviceHub/device/DeviceBase.h @@ -3,7 +3,7 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaProducer.h" +//#include "common/utils/QKafkaProducer.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -43,7 +43,7 @@ QString devType; QSerialPortUtil serialUtil; - QKafkaProducer kafkaProducer; +// QKafkaProducer kafkaProducer; QByteArray dataBuff; }; diff --git a/DeviceHub/device/FreqReplicator.cpp b/DeviceHub/device/FreqReplicator.cpp index 8767f90..ea50664 100644 --- a/DeviceHub/device/FreqReplicator.cpp +++ b/DeviceHub/device/FreqReplicator.cpp @@ -12,9 +12,9 @@ connect(this, &FreqReplicator::sendDataToDraw, ((DeviceHubWindow *)this->parent())->freqRepForm, &FreqReplicatorForm::drawDeviceFrameOnForm); - kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaProducer.createProducer(); +// kafkaProducer.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); +// kafkaProducer.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); +// kafkaProducer.createProducer(); this->protocol = DeviceProtocolBase::deviceProtocolFactory(devType); } @@ -29,7 +29,7 @@ { QByteArray buffer; - // freq replicator + // 频率信号放大器 buffer = QByteUtil::hexStringToBytes("AA550015010001000101010101010101010101010101010101EB"); buffer.append(QByteUtil::hexStringToBytes("AA550015020001000101010101010101010101010101010101E8")); @@ -40,12 +40,11 @@ { this->dataBuff.append(data); - std::cout << QByteUtil::binToHexString(dataBuff).toStdString() << std::endl; - QList frameList = protocol->extractFrameList(this->dataBuff); if (frameList.size() > 0) { + this->dataBuff.clear(); for (int i = 0; i < frameList.size(); i++) { QByteArray frameByte = frameList.at(i); @@ -81,7 +80,6 @@ void FreqReplicator::afterFramePhase(DeviceFrameBaseDto * frameDto) { - std::cout << "frame type: " << typeid(* frameDto).name() << std::endl; std::cout << QByteUtil::binToHexString(frameDto->rawFrame).toStdString() << std::endl; // 0. 输出到日志文件中 @@ -103,7 +101,7 @@ QJsonObject jsonObj = frameDto->toJSON(); jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); jsonObj.insert("deviceId", deviceId); - kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); +// kafkaProducer.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); } // 4. 在界面上简单显示相差数据结果 diff --git a/DeviceHub/device/FreqReplicator.h b/DeviceHub/device/FreqReplicator.h index 18bc01f..5702c28 100644 --- a/DeviceHub/device/FreqReplicator.h +++ b/DeviceHub/device/FreqReplicator.h @@ -1,4 +1,4 @@ -#ifndef FREQREPLICATOR_H +#ifndef FREQREPLICATOR_H #define FREQREPLICATOR_H #include @@ -16,15 +16,12 @@ void mockReceivData(); void afterFramePhase(DeviceFrameBaseDto * frameDto); -// void sendDataToSerial(QByteArray data); signals: void sendDataToDraw(DeviceFrameBaseDto * frameData); -// void sendCommandToDisplay(QJsonObject command); public slots: void dataReceivedHandler(QByteArray data); -// void commandReceivedHandler(QJsonObject command); }; #endif // FREQREPLICATOR_H diff --git a/DeviceHub/device/device.pri b/DeviceHub/device/device.pri index fedab85..06e82c0 100644 --- a/DeviceHub/device/device.pri +++ b/DeviceHub/device/device.pri @@ -1,18 +1,18 @@ HEADERS += $$PWD/DeviceBase.h -HEADERS += $$PWD/FrequencyTuning.h -HEADERS += $$PWD/SignalGenerator.h -HEADERS += $$PWD/TimeSwitcher.h -HEADERS += $$PWD/FreqSwitcher.h -HEADERS += $$PWD/TimeReplicator.h +#HEADERS += $$PWD/FrequencyTuning.h +#HEADERS += $$PWD/SignalGenerator.h +#HEADERS += $$PWD/TimeSwitcher.h +#HEADERS += $$PWD/FreqSwitcher.h +#HEADERS += $$PWD/TimeReplicator.h HEADERS += $$PWD/FreqReplicator.h -HEADERS += $$PWD/BCodeTerminal.h +#HEADERS += $$PWD/BCodeTerminal.h SOURCES += $$PWD/DeviceBase.cpp -SOURCES += $$PWD/FrequencyTuning.cpp -SOURCES += $$PWD/SignalGenerator.cpp -SOURCES += $$PWD/TimeSwitcher.cpp -SOURCES += $$PWD/FreqSwitcher.cpp -SOURCES += $$PWD/TimeReplicator.cpp +#SOURCES += $$PWD/FrequencyTuning.cpp +#SOURCES += $$PWD/SignalGenerator.cpp +#SOURCES += $$PWD/TimeSwitcher.cpp +#SOURCES += $$PWD/FreqSwitcher.cpp +#SOURCES += $$PWD/TimeReplicator.cpp SOURCES += $$PWD/FreqReplicator.cpp -SOURCES += $$PWD/BCodeTerminal.cpp +#SOURCES += $$PWD/BCodeTerminal.cpp diff --git a/ZXSSCJ.pro b/ZXSSCJ.pro index 0810c68..5eccd3a 100644 --- a/ZXSSCJ.pro +++ b/ZXSSCJ.pro @@ -4,8 +4,8 @@ #CONFIG += ordered #SUBDIRS += CounterAcq #计数器数据采集 -SUBDIRS += CounterAcqBM #6906计数器数据采集 +#SUBDIRS += CounterAcqBM #6906计数器数据采集 #SUBDIRS += PhaseCompAcq #比相仪数据采集 #SUBDIRS += DevStatusAcq -#SUBDIRS += DeviceHub # +SUBDIRS += DeviceHub # #SUBDIRS += HClockAcq #氢钟状态数据采集