diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/common/common.pri b/CounterAcq/common/common.pri index b80a640..73755bd 100644 --- a/CounterAcq/common/common.pri +++ b/CounterAcq/common/common.pri @@ -3,7 +3,6 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaUtil.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,7 +12,6 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaUtil.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/common/common.pri b/CounterAcq/common/common.pri index b80a640..73755bd 100644 --- a/CounterAcq/common/common.pri +++ b/CounterAcq/common/common.pri @@ -3,7 +3,6 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaUtil.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,7 +12,6 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaUtil.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp index 41a155c..2f01408 100644 --- a/CounterAcq/common/utils/SettingConfig.cpp +++ b/CounterAcq/common/utils/SettingConfig.cpp @@ -5,27 +5,7 @@ filename = QApplication::applicationDirPath() + "/conf/config.ini"; setting = new QSettings(this->filename, QSettings::IniFormat); - BAUD_RATE = getProperty("com", "baudRate").toInt(); - - NEED_KAFKA = getProperty("kafka", "needKafka").toInt(); - KAFKA_BROKERS = getProperty("kafka", "brokers").toString(); - KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString(); - KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString(); - NEED_SASL = getProperty("kafka", "needSasl").toInt(); - SASL_USERNAME = getProperty("kafka", "saslUsername").toString(); - SASL_PASSWORD = getProperty("kafka", "saslPassword").toString(); - - CLIENT_ID = getProperty("client", "clientId").toString(); - APP_KEY = getProperty("client", "appKey").toString(); - DEV_TYPES = getProperty("client", "devTypes").toString(); - SYSTEM = getProperty("client", "system").toString(); - WORK_TYPE = getProperty("client", "workMode").toString(); - MASTER = getProperty("client", "master").toInt(); - SERVER_PORT = getProperty("client", "serverPort").toInt(); - - BASE_URL = getProperty("http", "baseUrl").toString(); - - BASE_LOG_PATH = getProperty("log", "basePath").toString(); + init(); } @@ -33,3 +13,40 @@ QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName)); return var; } + +void SettingConfig::setConProperty(QString nodeName, QString keyName, QString value) { + this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); +} + +void SettingConfig::init() +{ + COM_NAME = getProperty("com", "comName").toString().split(","); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + + DEVICE_ID = getProperty("dev", "deviceId").toString().split(","); + DEV_CODE = getProperty("dev", "devCode").toString().split(","); + DEV_NAME = getProperty("dev", "devName").toString().split(","); + + WORK_TYPE = getProperty("client", "workMode").toString(); + + RECV_HOST = getProperty("recv", "host").toString(); + RECV_PORT = getProperty("recv", "port").toInt(); + + QString clockStr = getProperty("channel", "clock").toString(); + QList devList = clockStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList clockList = devList.at(i).split(","); + CLOCK_ARR.append(clockList); + } + + QString delayStr = getProperty("channel", "delay").toString(); + devList = delayStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList delayList = devList.at(i).split(","); + DELAY_ARR.append(delayList); + } + + BASE_LOG_PATH = getProperty("log", "basePath").toString(); +} diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/common/common.pri b/CounterAcq/common/common.pri index b80a640..73755bd 100644 --- a/CounterAcq/common/common.pri +++ b/CounterAcq/common/common.pri @@ -3,7 +3,6 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaUtil.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,7 +12,6 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaUtil.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp index 41a155c..2f01408 100644 --- a/CounterAcq/common/utils/SettingConfig.cpp +++ b/CounterAcq/common/utils/SettingConfig.cpp @@ -5,27 +5,7 @@ filename = QApplication::applicationDirPath() + "/conf/config.ini"; setting = new QSettings(this->filename, QSettings::IniFormat); - BAUD_RATE = getProperty("com", "baudRate").toInt(); - - NEED_KAFKA = getProperty("kafka", "needKafka").toInt(); - KAFKA_BROKERS = getProperty("kafka", "brokers").toString(); - KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString(); - KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString(); - NEED_SASL = getProperty("kafka", "needSasl").toInt(); - SASL_USERNAME = getProperty("kafka", "saslUsername").toString(); - SASL_PASSWORD = getProperty("kafka", "saslPassword").toString(); - - CLIENT_ID = getProperty("client", "clientId").toString(); - APP_KEY = getProperty("client", "appKey").toString(); - DEV_TYPES = getProperty("client", "devTypes").toString(); - SYSTEM = getProperty("client", "system").toString(); - WORK_TYPE = getProperty("client", "workMode").toString(); - MASTER = getProperty("client", "master").toInt(); - SERVER_PORT = getProperty("client", "serverPort").toInt(); - - BASE_URL = getProperty("http", "baseUrl").toString(); - - BASE_LOG_PATH = getProperty("log", "basePath").toString(); + init(); } @@ -33,3 +13,40 @@ QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName)); return var; } + +void SettingConfig::setConProperty(QString nodeName, QString keyName, QString value) { + this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); +} + +void SettingConfig::init() +{ + COM_NAME = getProperty("com", "comName").toString().split(","); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + + DEVICE_ID = getProperty("dev", "deviceId").toString().split(","); + DEV_CODE = getProperty("dev", "devCode").toString().split(","); + DEV_NAME = getProperty("dev", "devName").toString().split(","); + + WORK_TYPE = getProperty("client", "workMode").toString(); + + RECV_HOST = getProperty("recv", "host").toString(); + RECV_PORT = getProperty("recv", "port").toInt(); + + QString clockStr = getProperty("channel", "clock").toString(); + QList devList = clockStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList clockList = devList.at(i).split(","); + CLOCK_ARR.append(clockList); + } + + QString delayStr = getProperty("channel", "delay").toString(); + devList = delayStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList delayList = devList.at(i).split(","); + DELAY_ARR.append(delayList); + } + + BASE_LOG_PATH = getProperty("log", "basePath").toString(); +} diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h index 300023e..c462293 100644 --- a/CounterAcq/common/utils/SettingConfig.h +++ b/CounterAcq/common/utils/SettingConfig.h @@ -2,6 +2,7 @@ #define SETTINGCONFIG_H #include +#include #include #include @@ -25,27 +26,24 @@ * @title */ QVariant getProperty(QString nodeName, QString keyName); + void setConProperty(QString nodeName, QString keyName, QString value); + void init(); /******** 以下为需要的各类参数 ********/ + QStringList COM_NAME; int BAUD_RATE; - int NEED_KAFKA; - QString KAFKA_BROKERS; - QString KAFKA_DATA_TOPIC; - QString KAFKA_STATUS_TOPIC; - int NEED_SASL; - QString SASL_USERNAME; - QString SASL_PASSWORD; + QStringList DEVICE_ID; + QStringList DEV_CODE; + QStringList DEV_NAME; - QString CLIENT_ID; - QString APP_KEY; - QString DEV_TYPES; - QString SYSTEM; QString WORK_TYPE; - int MASTER; - quint16 SERVER_PORT; - QString BASE_URL; + QString RECV_HOST; + int RECV_PORT; + + QVector DELAY_ARR; + QVector CLOCK_ARR; QString BASE_LOG_PATH; diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/common/common.pri b/CounterAcq/common/common.pri index b80a640..73755bd 100644 --- a/CounterAcq/common/common.pri +++ b/CounterAcq/common/common.pri @@ -3,7 +3,6 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaUtil.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,7 +12,6 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaUtil.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp index 41a155c..2f01408 100644 --- a/CounterAcq/common/utils/SettingConfig.cpp +++ b/CounterAcq/common/utils/SettingConfig.cpp @@ -5,27 +5,7 @@ filename = QApplication::applicationDirPath() + "/conf/config.ini"; setting = new QSettings(this->filename, QSettings::IniFormat); - BAUD_RATE = getProperty("com", "baudRate").toInt(); - - NEED_KAFKA = getProperty("kafka", "needKafka").toInt(); - KAFKA_BROKERS = getProperty("kafka", "brokers").toString(); - KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString(); - KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString(); - NEED_SASL = getProperty("kafka", "needSasl").toInt(); - SASL_USERNAME = getProperty("kafka", "saslUsername").toString(); - SASL_PASSWORD = getProperty("kafka", "saslPassword").toString(); - - CLIENT_ID = getProperty("client", "clientId").toString(); - APP_KEY = getProperty("client", "appKey").toString(); - DEV_TYPES = getProperty("client", "devTypes").toString(); - SYSTEM = getProperty("client", "system").toString(); - WORK_TYPE = getProperty("client", "workMode").toString(); - MASTER = getProperty("client", "master").toInt(); - SERVER_PORT = getProperty("client", "serverPort").toInt(); - - BASE_URL = getProperty("http", "baseUrl").toString(); - - BASE_LOG_PATH = getProperty("log", "basePath").toString(); + init(); } @@ -33,3 +13,40 @@ QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName)); return var; } + +void SettingConfig::setConProperty(QString nodeName, QString keyName, QString value) { + this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); +} + +void SettingConfig::init() +{ + COM_NAME = getProperty("com", "comName").toString().split(","); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + + DEVICE_ID = getProperty("dev", "deviceId").toString().split(","); + DEV_CODE = getProperty("dev", "devCode").toString().split(","); + DEV_NAME = getProperty("dev", "devName").toString().split(","); + + WORK_TYPE = getProperty("client", "workMode").toString(); + + RECV_HOST = getProperty("recv", "host").toString(); + RECV_PORT = getProperty("recv", "port").toInt(); + + QString clockStr = getProperty("channel", "clock").toString(); + QList devList = clockStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList clockList = devList.at(i).split(","); + CLOCK_ARR.append(clockList); + } + + QString delayStr = getProperty("channel", "delay").toString(); + devList = delayStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList delayList = devList.at(i).split(","); + DELAY_ARR.append(delayList); + } + + BASE_LOG_PATH = getProperty("log", "basePath").toString(); +} diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h index 300023e..c462293 100644 --- a/CounterAcq/common/utils/SettingConfig.h +++ b/CounterAcq/common/utils/SettingConfig.h @@ -2,6 +2,7 @@ #define SETTINGCONFIG_H #include +#include #include #include @@ -25,27 +26,24 @@ * @title */ QVariant getProperty(QString nodeName, QString keyName); + void setConProperty(QString nodeName, QString keyName, QString value); + void init(); /******** 以下为需要的各类参数 ********/ + QStringList COM_NAME; int BAUD_RATE; - int NEED_KAFKA; - QString KAFKA_BROKERS; - QString KAFKA_DATA_TOPIC; - QString KAFKA_STATUS_TOPIC; - int NEED_SASL; - QString SASL_USERNAME; - QString SASL_PASSWORD; + QStringList DEVICE_ID; + QStringList DEV_CODE; + QStringList DEV_NAME; - QString CLIENT_ID; - QString APP_KEY; - QString DEV_TYPES; - QString SYSTEM; QString WORK_TYPE; - int MASTER; - quint16 SERVER_PORT; - QString BASE_URL; + QString RECV_HOST; + int RECV_PORT; + + QVector DELAY_ARR; + QVector CLOCK_ARR; QString BASE_LOG_PATH; diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini index c2370ca..c4f2d8d 100644 --- a/CounterAcq/conf/config.ini +++ b/CounterAcq/conf/config.ini @@ -1,26 +1,22 @@ [com] +comName="ttyr0" baudRate=115200 -[kafka] -needKafka=1 -brokers="111.198.10.15:20104" -dataTopic="clock-data" -statusTopic="dev-status" -needSasl=1 -saslUsername="admin" -saslPassword="casicss" +[dev] +deviceId="2110001" +devCode="2110001" +devName="离线计数器01" + +[recv] +host="127.0.0.1" +port=7000 [client] -clientId="clock" -appKey="bd347bdd20943d2db8af558c3712a357" -devTypes="01" -system="clock" -workMode="mock" -master=1 -serverPort=5905 +workMode=mock -[http] -baseUrl="http://111.198.10.15:11410" +[channel] +clock="3001,3002,3003,3004,3005,3006,0,0,0,0,1,2,3,4,5,6" +delay="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" [log] basePath="/home/admin/Qt/ZXSSCJ-Release/CounterAcq/logs/" diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/common/common.pri b/CounterAcq/common/common.pri index b80a640..73755bd 100644 --- a/CounterAcq/common/common.pri +++ b/CounterAcq/common/common.pri @@ -3,7 +3,6 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaUtil.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,7 +12,6 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaUtil.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp index 41a155c..2f01408 100644 --- a/CounterAcq/common/utils/SettingConfig.cpp +++ b/CounterAcq/common/utils/SettingConfig.cpp @@ -5,27 +5,7 @@ filename = QApplication::applicationDirPath() + "/conf/config.ini"; setting = new QSettings(this->filename, QSettings::IniFormat); - BAUD_RATE = getProperty("com", "baudRate").toInt(); - - NEED_KAFKA = getProperty("kafka", "needKafka").toInt(); - KAFKA_BROKERS = getProperty("kafka", "brokers").toString(); - KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString(); - KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString(); - NEED_SASL = getProperty("kafka", "needSasl").toInt(); - SASL_USERNAME = getProperty("kafka", "saslUsername").toString(); - SASL_PASSWORD = getProperty("kafka", "saslPassword").toString(); - - CLIENT_ID = getProperty("client", "clientId").toString(); - APP_KEY = getProperty("client", "appKey").toString(); - DEV_TYPES = getProperty("client", "devTypes").toString(); - SYSTEM = getProperty("client", "system").toString(); - WORK_TYPE = getProperty("client", "workMode").toString(); - MASTER = getProperty("client", "master").toInt(); - SERVER_PORT = getProperty("client", "serverPort").toInt(); - - BASE_URL = getProperty("http", "baseUrl").toString(); - - BASE_LOG_PATH = getProperty("log", "basePath").toString(); + init(); } @@ -33,3 +13,40 @@ QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName)); return var; } + +void SettingConfig::setConProperty(QString nodeName, QString keyName, QString value) { + this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); +} + +void SettingConfig::init() +{ + COM_NAME = getProperty("com", "comName").toString().split(","); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + + DEVICE_ID = getProperty("dev", "deviceId").toString().split(","); + DEV_CODE = getProperty("dev", "devCode").toString().split(","); + DEV_NAME = getProperty("dev", "devName").toString().split(","); + + WORK_TYPE = getProperty("client", "workMode").toString(); + + RECV_HOST = getProperty("recv", "host").toString(); + RECV_PORT = getProperty("recv", "port").toInt(); + + QString clockStr = getProperty("channel", "clock").toString(); + QList devList = clockStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList clockList = devList.at(i).split(","); + CLOCK_ARR.append(clockList); + } + + QString delayStr = getProperty("channel", "delay").toString(); + devList = delayStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList delayList = devList.at(i).split(","); + DELAY_ARR.append(delayList); + } + + BASE_LOG_PATH = getProperty("log", "basePath").toString(); +} diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h index 300023e..c462293 100644 --- a/CounterAcq/common/utils/SettingConfig.h +++ b/CounterAcq/common/utils/SettingConfig.h @@ -2,6 +2,7 @@ #define SETTINGCONFIG_H #include +#include #include #include @@ -25,27 +26,24 @@ * @title */ QVariant getProperty(QString nodeName, QString keyName); + void setConProperty(QString nodeName, QString keyName, QString value); + void init(); /******** 以下为需要的各类参数 ********/ + QStringList COM_NAME; int BAUD_RATE; - int NEED_KAFKA; - QString KAFKA_BROKERS; - QString KAFKA_DATA_TOPIC; - QString KAFKA_STATUS_TOPIC; - int NEED_SASL; - QString SASL_USERNAME; - QString SASL_PASSWORD; + QStringList DEVICE_ID; + QStringList DEV_CODE; + QStringList DEV_NAME; - QString CLIENT_ID; - QString APP_KEY; - QString DEV_TYPES; - QString SYSTEM; QString WORK_TYPE; - int MASTER; - quint16 SERVER_PORT; - QString BASE_URL; + QString RECV_HOST; + int RECV_PORT; + + QVector DELAY_ARR; + QVector CLOCK_ARR; QString BASE_LOG_PATH; diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini index c2370ca..c4f2d8d 100644 --- a/CounterAcq/conf/config.ini +++ b/CounterAcq/conf/config.ini @@ -1,26 +1,22 @@ [com] +comName="ttyr0" baudRate=115200 -[kafka] -needKafka=1 -brokers="111.198.10.15:20104" -dataTopic="clock-data" -statusTopic="dev-status" -needSasl=1 -saslUsername="admin" -saslPassword="casicss" +[dev] +deviceId="2110001" +devCode="2110001" +devName="离线计数器01" + +[recv] +host="127.0.0.1" +port=7000 [client] -clientId="clock" -appKey="bd347bdd20943d2db8af558c3712a357" -devTypes="01" -system="clock" -workMode="mock" -master=1 -serverPort=5905 +workMode=mock -[http] -baseUrl="http://111.198.10.15:11410" +[channel] +clock="3001,3002,3003,3004,3005,3006,0,0,0,0,1,2,3,4,5,6" +delay="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" [log] basePath="/home/admin/Qt/ZXSSCJ-Release/CounterAcq/logs/" diff --git a/CounterAcq/protocol/protocol.pri b/CounterAcq/protocol/protocol.pri index 8aa7808..364400c 100644 --- a/CounterAcq/protocol/protocol.pri +++ b/CounterAcq/protocol/protocol.pri @@ -1,8 +1,6 @@ -#SOURCES += $$PWD/CounterProtocolBM.cpp SOURCES += $$PWD/CounterProtocolXH.cpp SOURCES += $$PWD/dto/CounterDataDto.cpp -#HEADERS += $$PWD/CounterProtocolBM.h HEADERS += $$PWD/CounterProtocolXH.h HEADERS += $$PWD/dto/CounterDataDto.h diff --git a/CounterAcq/CounterAcq.pro b/CounterAcq/CounterAcq.pro index 38de4cb..610eec9 100644 --- a/CounterAcq/CounterAcq.pro +++ b/CounterAcq/CounterAcq.pro @@ -22,8 +22,3 @@ qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target - -unix:!macx: LIBS += -L$$PWD/lib/librdkafka/ -lrdkafka -lrdkafka++ - -INCLUDEPATH += $$PWD/include/librdkafka -DEPENDPATH += $$PWD/include/librdkafka diff --git a/CounterAcq/CounterDevice.cpp b/CounterAcq/CounterDevice.cpp index 97c6e6d..318dff7 100644 --- a/CounterAcq/CounterDevice.cpp +++ b/CounterAcq/CounterDevice.cpp @@ -8,10 +8,7 @@ { connect(&this->serialUtil, &QSerialPortUtil::dataRecieved, this, &CounterDevice::dataReceivedHandler); - - kafkaUtil.setBrokers(SettingConfig::getInstance().KAFKA_BROKERS); - kafkaUtil.setTopic(SettingConfig::getInstance().KAFKA_DATA_TOPIC); - kafkaUtil.createProducer(); + udpClient = new QUdpSocket(this); } CounterDevice::~CounterDevice() @@ -120,24 +117,36 @@ QLogUtil::writeChannelDataLogByDate(date, chFilename, channelDataStr); - // 3. 输出到中间件,执行后续处理过程 - if (SettingConfig::getInstance().NEED_KAFKA == 1) - { - QJsonObject jsonObj = counterData->toJSON(i - 1); - jsonObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - jsonObj.insert("master", SettingConfig::getInstance().MASTER); - jsonObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact))); - } + // 取到钟编号和时延值 + QString openClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(i - 1); + QString closeClock = SettingConfig::getInstance().CLOCK_ARR.at(0).at(counterData->channelRefId - 1); + QString delay = SettingConfig::getInstance().DELAY_ARR.at(0).at(i - 1); + + // 3. 通过UDP发送到本地的Java后端进行存库处理 + QJsonObject jsonObj = counterData->toJSON(i - 1); + jsonObj.insert("deviceId", deviceId); + jsonObj.insert("devCode", devCode); + QJsonObject data = jsonObj.take("data").toObject(); + data.insert("openClock", openClock); + data.insert("closeClock", closeClock); + double value = data.find("dataValue")->toString().toDouble(); + value += delay.toDouble() * 1E-9; + data.insert("dataValue", QString::number(value, 'f', 12)); + jsonObj.insert("data", data); + udpClient->writeDatagram(QString(QJsonDocument(jsonObj).toJson(QJsonDocument::Compact)).toLocal8Bit(), QHostAddress(SettingConfig::getInstance().RECV_HOST), SettingConfig::getInstance().RECV_PORT); } } // 4. 在界面上简单显示相差数据结果 emit this->sendDataToDraw(counterData); +} - QJsonObject statusObj = counterData->toStatusJSON(); - statusObj.insert("clientId", SettingConfig::getInstance().CLIENT_ID); - statusObj.insert("master", SettingConfig::getInstance().MASTER); - statusObj.insert("deviceId", deviceId); - kafkaUtil.produceMessage(SettingConfig::getInstance().KAFKA_STATUS_TOPIC, QString(QJsonDocument(statusObj).toJson(QJsonDocument::Compact))); +void CounterDevice::onClockChanged() +{ + +} + +void CounterDevice::onDelayChanged() +{ + } diff --git a/CounterAcq/CounterDevice.h b/CounterAcq/CounterDevice.h index d126933..5ed1949 100644 --- a/CounterAcq/CounterDevice.h +++ b/CounterAcq/CounterDevice.h @@ -5,7 +5,6 @@ #include #include "common/utils/QSerialPortUtil.h" -#include "common/utils/QKafkaUtil.h" #include "common/utils/QByteUtil.h" #include "common/utils/QLogUtil.h" #include "common/utils/SettingConfig.h" @@ -34,8 +33,8 @@ QString comName; int baudRate; + QUdpSocket * udpClient; QSerialPortUtil serialUtil; - QKafkaUtil kafkaUtil; QByteArray dataBuff; QMap bench; @@ -49,6 +48,9 @@ public slots: void dataReceivedHandler(QByteArray data); + void onClockChanged(); + void onDelayChanged(); + }; #endif // COUNTERDEVICE_H diff --git a/CounterAcq/CounterWindow.cpp b/CounterAcq/CounterWindow.cpp index 35c5ac8..9b14e05 100644 --- a/CounterAcq/CounterWindow.cpp +++ b/CounterAcq/CounterWindow.cpp @@ -22,7 +22,7 @@ this->setWindowFlags(Qt::FramelessWindowHint); // 窗口大小为占满一屏 - QRect screenRect = QApplication::desktop()->screenGeometry(); + QRect screenRect = QApplication::desktop()->availableGeometry(); resize(screenRect.width(), screenRect.height()); // 将窗口移动到左上角 @@ -35,59 +35,37 @@ ui->scrollArea->setGeometry(0, 60, screenRect.width(), screenRect.height() - 60); ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); - httpReq = new HttpRequestController(this); - // 1. 获取访问接口需要的token - int retCode = this->initHttpToken(); - if (retCode != 200) + ui->devSelect->clear(); + for (int i = 0; i < SettingConfig::getInstance().DEV_CODE.size(); i++) { - QMessageBox::information(this, "错误", "获取http请求的token失败,程序即将退出"); + ui->devSelect->addItem(SettingConfig::getInstance().DEV_NAME.at(i), SettingConfig::getInstance().DEV_CODE.at(i)); - QTimer::singleShot(1000, qApp, SLOT(quit())); + CounterDevice * device = new CounterDevice(this); + deviceList.append(device); + + device->setComName(SettingConfig::getInstance().COM_NAME.at(i)); + device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); + device->setDevCode(SettingConfig::getInstance().DEV_CODE.at(i)); + device->setDeviceId(SettingConfig::getInstance().DEVICE_ID.at(i)); + + connect(device, &CounterDevice::sendDataToDraw, + this, &CounterWindow::drawCounterDataOnPage); + + device->initSerialPort(); + + QThread::msleep(200); } - // 2. 获取字典值:设备类型 - retCode = this->initDictDeviceTypes(); - // 3. 获取计数器设备列表 - QJsonObject devListRes = this->initDeviceList(); - if (devListRes.find("code")->toInt() == 200) + // 5. 设置下拉框的样式 + QStandardItemModel * model = qobject_cast(ui->devSelect->model()); + for (int i = 0; i < model->rowCount(); ++i) { - ui->devSelect->clear(); - - // 4. 将获取到的设备添加到下拉列表框中 - QJsonArray devArray = devListRes.find("data")->toArray(); - for (int i = 0; i < devArray.size(); i++) - { - QJsonObject devItem = devArray.at(i).toObject(); - ui->devSelect->addItem(devItem.find("deviceName")->toString(), devItem.find("deviceNo")->toString()); - - CounterDevice * device = new CounterDevice(this); - deviceList.append(device); - - device->setComName(devItem.find("linkComName")->toString()); - device->setBaudRate(SettingConfig::getInstance().BAUD_RATE); - device->setDevCode(devItem.find("deviceNo")->toString()); - device->setDeviceId(devItem.find("deviceId")->toString()); - - connect(device, &CounterDevice::sendDataToDraw, - this, &CounterWindow::drawCounterDataOnPage); - - device->initSerialPort(); - - QThread::msleep(200); - } - // 5. 设置下拉框的样式 - QStandardItemModel * model = qobject_cast(ui->devSelect->model()); - for (int i = 0; i < model->rowCount(); ++i) - { - QStandardItem * item = model->item(i); - item->setSizeHint({ 0, 30 }); - } + QStandardItem * item = model->item(i); + item->setSizeHint({ 0, 30 }); } // 6. 绘制一个设备的多个通道数据面板 this->generateWidgetForDevice(); - - HttpServer::instance().run(QHostAddress::Any, SettingConfig::getInstance().SERVER_PORT); } CounterWindow::~CounterWindow() @@ -162,6 +140,34 @@ validLabel->setStyleSheet("margin-left:20;"); vbox->addWidget(validLabel); + QLabel * clockLabel = new QLabel(); + clockLabel->setText("钟编号"); + clockLabel->setFont(labelFont); + clockLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(clockLabel); + QLineEdit * clockValue = new QLineEdit(); + clockValue->setFixedWidth(60); + clockValue->setFont(labelFont); + vbox->addWidget(clockValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(clockValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onClockChanged); + } + + QLabel * delayLabel = new QLabel(); + delayLabel->setText("时延值(ns)"); + delayLabel->setFont(labelFont); + delayLabel->setStyleSheet("margin-left:20;"); + vbox->addWidget(delayLabel); + QLineEdit * delayValue = new QLineEdit(); + delayValue->setFixedWidth(100); + delayValue->setFont(labelFont); + vbox->addWidget(delayValue); + for (int i = 0; i < deviceList.size(); i++) + { + connect(delayValue, &QLineEdit::textChanged, deviceList.at(i), &CounterDevice::onDelayChanged); + } + QSpacerItem * hSpace = new QSpacerItem(20, 20); hSpace->changeSize(20, 20, QSizePolicy::Expanding); vbox->addItem(hSpace); @@ -195,26 +201,11 @@ ((QLineEdit *)channelBox->children().at(6))->setText(counterData->frameId); ((QLineEdit *)channelBox->children().at(8))->setText(QString("%1").arg(counterData->channelRefId)); ((QLabel *)channelBox->children().at(9))->setText(counterData->channelActiveArray.at(i) == "1" ? "有效" : "无效"); + ((QLineEdit *)channelBox->children().at(11))->setText(SettingConfig::getInstance().CLOCK_ARR.at(0).at(i)); + ((QLineEdit *)channelBox->children().at(13))->setText(SettingConfig::getInstance().DELAY_ARR.at(0).at(i)); } } -int CounterWindow::initHttpToken() -{ - QJsonObject response = httpReq->getTokenByClientId(SettingConfig::getInstance().CLIENT_ID, - SettingConfig::getInstance().APP_KEY); - return response.find("code")->toInt(); -} -int CounterWindow::initDictDeviceTypes() -{ - QJsonObject response = httpReq->initDictDeviceType(); - return response.find("code")->toInt(); -} -QJsonObject CounterWindow::initDeviceList() -{ - QJsonObject response = httpReq->initDeviceList(SettingConfig::getInstance().DEV_TYPES, SettingConfig::getInstance().SYSTEM); - return response; -} - void CounterWindow::on_exitButt_clicked() { QApplication::exit(0); diff --git a/CounterAcq/CounterWindow.h b/CounterAcq/CounterWindow.h index 084bb06..bef3646 100644 --- a/CounterAcq/CounterWindow.h +++ b/CounterAcq/CounterWindow.h @@ -8,7 +8,6 @@ #include "common/utils/SettingConfig.h" #include "common/HttpRequestController.h" -#include "common/HttpServer.h" #include "CounterDevice.h" namespace Ui { @@ -32,9 +31,6 @@ void on_minButt_clicked(); private: - int initHttpToken(); - int initDictDeviceTypes(); - QJsonObject initDeviceList(); Ui::CounterWindow *ui; diff --git a/CounterAcq/common/common.pri b/CounterAcq/common/common.pri index b80a640..73755bd 100644 --- a/CounterAcq/common/common.pri +++ b/CounterAcq/common/common.pri @@ -3,7 +3,6 @@ SOURCES += $$PWD/utils/QByteUtil.cpp SOURCES += $$PWD/utils/QSerialPortUtil.cpp SOURCES += $$PWD/utils/QLogUtil.cpp -SOURCES += $$PWD/utils/QKafkaUtil.cpp SOURCES += $$PWD/utils/HttpRequestUtil.cpp SOURCES += $$PWD/utils/MD5.cpp SOURCES += $$PWD/HttpRequestController.cpp @@ -13,7 +12,6 @@ HEADERS += $$PWD/utils/QByteUtil.h HEADERS += $$PWD/utils/QSerialPortUtil.h HEADERS += $$PWD/utils/QLogUtil.h -HEADERS += $$PWD/utils/QKafkaUtil.h HEADERS += $$PWD/utils/HttpRequestUtil.h HEADERS += $$PWD/utils/DefHead.h HEADERS += $$PWD/utils/MD5.h diff --git a/CounterAcq/common/utils/SettingConfig.cpp b/CounterAcq/common/utils/SettingConfig.cpp index 41a155c..2f01408 100644 --- a/CounterAcq/common/utils/SettingConfig.cpp +++ b/CounterAcq/common/utils/SettingConfig.cpp @@ -5,27 +5,7 @@ filename = QApplication::applicationDirPath() + "/conf/config.ini"; setting = new QSettings(this->filename, QSettings::IniFormat); - BAUD_RATE = getProperty("com", "baudRate").toInt(); - - NEED_KAFKA = getProperty("kafka", "needKafka").toInt(); - KAFKA_BROKERS = getProperty("kafka", "brokers").toString(); - KAFKA_DATA_TOPIC = getProperty("kafka", "dataTopic").toString(); - KAFKA_STATUS_TOPIC = getProperty("kafka", "statusTopic").toString(); - NEED_SASL = getProperty("kafka", "needSasl").toInt(); - SASL_USERNAME = getProperty("kafka", "saslUsername").toString(); - SASL_PASSWORD = getProperty("kafka", "saslPassword").toString(); - - CLIENT_ID = getProperty("client", "clientId").toString(); - APP_KEY = getProperty("client", "appKey").toString(); - DEV_TYPES = getProperty("client", "devTypes").toString(); - SYSTEM = getProperty("client", "system").toString(); - WORK_TYPE = getProperty("client", "workMode").toString(); - MASTER = getProperty("client", "master").toInt(); - SERVER_PORT = getProperty("client", "serverPort").toInt(); - - BASE_URL = getProperty("http", "baseUrl").toString(); - - BASE_LOG_PATH = getProperty("log", "basePath").toString(); + init(); } @@ -33,3 +13,40 @@ QVariant var = this->setting->value(QString("/%1/%2").arg(nodeName).arg(keyName)); return var; } + +void SettingConfig::setConProperty(QString nodeName, QString keyName, QString value) { + this->setting->setValue(QString("/%1/%2").arg(nodeName).arg(keyName),value); +} + +void SettingConfig::init() +{ + COM_NAME = getProperty("com", "comName").toString().split(","); + BAUD_RATE = getProperty("com", "baudRate").toInt(); + + DEVICE_ID = getProperty("dev", "deviceId").toString().split(","); + DEV_CODE = getProperty("dev", "devCode").toString().split(","); + DEV_NAME = getProperty("dev", "devName").toString().split(","); + + WORK_TYPE = getProperty("client", "workMode").toString(); + + RECV_HOST = getProperty("recv", "host").toString(); + RECV_PORT = getProperty("recv", "port").toInt(); + + QString clockStr = getProperty("channel", "clock").toString(); + QList devList = clockStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList clockList = devList.at(i).split(","); + CLOCK_ARR.append(clockList); + } + + QString delayStr = getProperty("channel", "delay").toString(); + devList = delayStr.split(";"); + for (int i = 0; i < devList.size(); i++) + { + QStringList delayList = devList.at(i).split(","); + DELAY_ARR.append(delayList); + } + + BASE_LOG_PATH = getProperty("log", "basePath").toString(); +} diff --git a/CounterAcq/common/utils/SettingConfig.h b/CounterAcq/common/utils/SettingConfig.h index 300023e..c462293 100644 --- a/CounterAcq/common/utils/SettingConfig.h +++ b/CounterAcq/common/utils/SettingConfig.h @@ -2,6 +2,7 @@ #define SETTINGCONFIG_H #include +#include #include #include @@ -25,27 +26,24 @@ * @title */ QVariant getProperty(QString nodeName, QString keyName); + void setConProperty(QString nodeName, QString keyName, QString value); + void init(); /******** 以下为需要的各类参数 ********/ + QStringList COM_NAME; int BAUD_RATE; - int NEED_KAFKA; - QString KAFKA_BROKERS; - QString KAFKA_DATA_TOPIC; - QString KAFKA_STATUS_TOPIC; - int NEED_SASL; - QString SASL_USERNAME; - QString SASL_PASSWORD; + QStringList DEVICE_ID; + QStringList DEV_CODE; + QStringList DEV_NAME; - QString CLIENT_ID; - QString APP_KEY; - QString DEV_TYPES; - QString SYSTEM; QString WORK_TYPE; - int MASTER; - quint16 SERVER_PORT; - QString BASE_URL; + QString RECV_HOST; + int RECV_PORT; + + QVector DELAY_ARR; + QVector CLOCK_ARR; QString BASE_LOG_PATH; diff --git a/CounterAcq/conf/config.ini b/CounterAcq/conf/config.ini index c2370ca..c4f2d8d 100644 --- a/CounterAcq/conf/config.ini +++ b/CounterAcq/conf/config.ini @@ -1,26 +1,22 @@ [com] +comName="ttyr0" baudRate=115200 -[kafka] -needKafka=1 -brokers="111.198.10.15:20104" -dataTopic="clock-data" -statusTopic="dev-status" -needSasl=1 -saslUsername="admin" -saslPassword="casicss" +[dev] +deviceId="2110001" +devCode="2110001" +devName="离线计数器01" + +[recv] +host="127.0.0.1" +port=7000 [client] -clientId="clock" -appKey="bd347bdd20943d2db8af558c3712a357" -devTypes="01" -system="clock" -workMode="mock" -master=1 -serverPort=5905 +workMode=mock -[http] -baseUrl="http://111.198.10.15:11410" +[channel] +clock="3001,3002,3003,3004,3005,3006,0,0,0,0,1,2,3,4,5,6" +delay="0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" [log] basePath="/home/admin/Qt/ZXSSCJ-Release/CounterAcq/logs/" diff --git a/CounterAcq/protocol/protocol.pri b/CounterAcq/protocol/protocol.pri index 8aa7808..364400c 100644 --- a/CounterAcq/protocol/protocol.pri +++ b/CounterAcq/protocol/protocol.pri @@ -1,8 +1,6 @@ -#SOURCES += $$PWD/CounterProtocolBM.cpp SOURCES += $$PWD/CounterProtocolXH.cpp SOURCES += $$PWD/dto/CounterDataDto.cpp -#HEADERS += $$PWD/CounterProtocolBM.h HEADERS += $$PWD/CounterProtocolXH.h HEADERS += $$PWD/dto/CounterDataDto.h diff --git a/ZXSSCJ.pro b/ZXSSCJ.pro index 1e18b47..64d5621 100644 --- a/ZXSSCJ.pro +++ b/ZXSSCJ.pro @@ -4,8 +4,5 @@ #CONFIG += ordered SUBDIRS += CounterAcq #计数器数据采集 -#SUBDIRS += CounterAcqBM #6906计数器数据采集 -SUBDIRS += PhaseCompAcq #比相仪数据采集 -#SUBDIRS += DevStatusAcq -SUBDIRS += DeviceHub # -#SUBDIRS += HClockAcq #氢钟状态数据采集 +#SUBDIRS += PhaseCompAcq #比相仪数据采集 +#SUBDIRS += DeviceHub #