#include "OtherConfig.h" #include "ui_OtherConfig.h" #include #include #include #include #include #include "ftpclient.h" COtherConfig::COtherConfig(QWidget *parent) : QWidget(parent), ui(new Ui::COtherConfig) { ui->setupUi(this); ui->widget->setProperty("flag", "Title"); ui->widget_2->setProperty("flag", "normal"); QRegExp exp("[0-9\\.-]+$"); QValidator *Validator = new QRegExpValidator(exp); ui->lineEdit_Trigger->setValidator(Validator); ui->lineEdit_peaktopeak->setValidator(Validator); ui->radioButton_closeIO->setChecked(1); LoadWorkingConditionConfig(); get_status = false; } COtherConfig::~COtherConfig() { delete ui; } void COtherConfig::LoadWorkingConditionConfig() { #ifdef Q_OS_WIN32 QString fileName = QCoreApplication::applicationDirPath() + "\\config\\TriggerConfig.json"; #endif #ifdef Q_OS_LINUX QString fileName = QCoreApplication::applicationDirPath() + "/config/TriggerConfig.json"; #endif if(!fileName.isEmpty()) { qDebug() << "打开" << fileName ; QFile file(fileName); file.open(QIODevice::ReadOnly | QIODevice::Text); QString value = file.readAll(); file.close(); QJsonParseError parseJsonErr; QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr); if (!(parseJsonErr.error == QJsonParseError::NoError)) { QMessageBox::about(NULL, "提示", "读取文件错误!"); return; } QJsonObject jsonObject = document.object(); if(jsonObject.contains(QStringLiteral("TriggerBuffer"))) { QJsonObject TriggerBufferObj = jsonObject["TriggerBuffer"].toObject(); QJsonObject TriggerBufferOption = TriggerBufferObj["option"].toObject(); QString strAfterTime = TriggerBufferOption["afterTime"].toString(); QString strBeforeTime = TriggerBufferOption["beforeTime"].toString(); m_strTriggerTime = QString("%1").arg(strAfterTime.toInt() + strBeforeTime.toInt()); ui->lineEdit_Trigger->setText(m_strTriggerTime); } } #ifdef Q_OS_WIN32 fileName = QCoreApplication::applicationDirPath() + "\\config\\ConfidenceDegree.json"; #endif #ifdef Q_OS_LINUX fileName = QCoreApplication::applicationDirPath() + "/config/ConfidenceDegree.json"; #endif if(!fileName.isEmpty()) { qDebug() << "打开" << fileName ; QFile file(fileName); file.open(QIODevice::ReadOnly | QIODevice::Text); QString value = file.readAll(); file.close(); QJsonParseError parseJsonErr; QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr); if (!(parseJsonErr.error == QJsonParseError::NoError)) { QMessageBox::about(NULL, "提示", "读取文件错误!"); return; } QJsonObject jsonObject = document.object(); int confidence_degree = jsonObject["confidence_degree"].toInt(); int section_num = jsonObject["section_num"].toInt(); m_strConfidence = QString("%1").arg(confidence_degree); m_strSegments = QString("%1").arg(section_num); } //读取ini #ifdef Q_OS_WIN32 QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini",QSettings::IniFormat); #endif #ifdef Q_OS_LINUX QSettings settingsread(QCoreApplication::applicationDirPath() + "/config/config.ini",QSettings::IniFormat); #endif settingsread.setIniCodec(QTextCodec::codecForName("UTF8")); g_strProject = settingsread.value("main/Project").toString(); QTextCodec* codec = QTextCodec::codecForName("UTF-8");//添加编码格式 QTextCodec::setCodecForLocale(codec); QString str = codec->toUnicode(g_strProject.toLatin1()); qDebug() << "str" << str << QString::fromLocal8Bit(str.toLatin1()) << QString::fromLocal8Bit(g_strProject.toLatin1()) << endl; qDebug() << "code" << QTextCodec::codecForLocale()->name() << endl; ui->textEdit_project->setText(str); ui->textEdit_version->setText(codec->toUnicode(g_strVersion.toLatin1())); for (int i = 0; i < g_ChannelBaseInfo.size(); i++) { if(g_ChannelBaseInfo[i].channelType == "TACHOMETER"){ ui->comboBox_ch->addItem(g_ChannelBaseInfo[i].channelName); }else if(g_ChannelBaseInfo[i].channelType == "PROXIMETER"){ ui->comboBox_ch2->addItem(g_ChannelBaseInfo[i].channelName); } } ui->comboBox_logic->addItem("与"); ui->comboBox_logic->addItem("或"); #ifdef Q_OS_WIN32 fileName = QCoreApplication::applicationDirPath() + "\\config\\ZeroDrift.json"; #endif #ifdef Q_OS_LINUX fileName = QCoreApplication::applicationDirPath() + "/config/ZeroDrift.json"; #endif if(!fileName.isEmpty()) { qDebug() << "打开" << fileName ; QFile file(fileName); file.open(QIODevice::ReadOnly | QIODevice::Text); QString value = file.readAll(); file.close(); QJsonParseError parseJsonErr; QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr); if (!(parseJsonErr.error == QJsonParseError::NoError)) { QMessageBox::about(NULL, "提示", "读取文件错误!"); return; } QJsonObject jsonObject = document.object(); QJsonObject tachometerObj = jsonObject["tachometerObj"].toObject(); QJsonObject ref_channelObj = jsonObject["ref_channel"].toObject(); int tachometerSlot = tachometerObj["slot"].toInt(); int tachometerChannel = tachometerObj["channel"].toInt(); int ref_channelObjSlot = ref_channelObj["slot"].toInt(); int ref_channelObjChannel = ref_channelObj["channel"].toInt(); double ref_channelObjpeaktopeak = ref_channelObj["peaktopeak"].toDouble(); int logic = jsonObject["logic"].toInt(); int operation = jsonObject["operation"].toInt(); for (int i = 0; i < g_ChannelBaseInfo.size(); i++) { if(g_ChannelBaseInfo[i].bordNo == tachometerSlot && \ g_ChannelBaseInfo[i].channelNoInBoard == tachometerChannel){ ui->comboBox_ch->setCurrentText(g_ChannelBaseInfo[i].channelName); } if(g_ChannelBaseInfo[i].bordNo == ref_channelObjSlot && \ g_ChannelBaseInfo[i].channelNoInBoard == ref_channelObjChannel){ ui->comboBox_ch2->setCurrentText(g_ChannelBaseInfo[i].channelName); } } QString str = QString("%1").arg(ref_channelObjpeaktopeak); ui->lineEdit_peaktopeak->setText(str); if(logic){ ui->comboBox_logic->setCurrentText("或"); }else{ ui->comboBox_logic->setCurrentText("与"); } if(operation){ ui->radioButton_open->setChecked(1); ui->radioButton_close->setChecked(0); }else{ ui->radioButton_open->setChecked(0); ui->radioButton_close->setChecked(1); } } } void COtherConfig::on_pushButto_Trigger_clicked() { QString str = ui->lineEdit_Trigger->text(); if(str.toInt() > 300 || str.toInt() <= 0){ QMessageBox::information(this, QStringLiteral("提示"), "请填写正确的触发时长!"); ui->lineEdit_Trigger->setText(m_strTriggerTime); return; } m_strTriggerTime = str; #ifdef Q_OS_WIN32 QString fileName = QCoreApplication::applicationDirPath() + "\\config\\TriggerConfig.json"; #endif #ifdef Q_OS_LINUX QString fileName = QCoreApplication::applicationDirPath() + "/config/TriggerConfig.json"; #endif if(!fileName.isEmpty()) { qDebug() << "打开" << fileName ; QFile file(fileName); file.open(QIODevice::ReadOnly | QIODevice::Text); QString value = file.readAll(); file.close(); QJsonParseError parseJsonErr; QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr); if (!(parseJsonErr.error == QJsonParseError::NoError)) { QMessageBox::about(NULL, "提示", "读取文件错误!"); return; } QJsonObject jsonObject = document.object(); if(jsonObject.contains(QStringLiteral("TriggerBuffer"))) { int AfterTime = ui->lineEdit_Trigger->text().toInt()/2; int BeforeTime = ui->lineEdit_Trigger->text().toInt() - AfterTime; QJsonObject tempObj,optionObj; tempObj["afterTime"] = QString("%1").arg(AfterTime); tempObj["beforeTime"] = QString("%1").arg(BeforeTime); optionObj["option"] = tempObj; jsonObject["TriggerBuffer"] = optionObj; } QJsonDocument jsonDoc; jsonDoc.setObject(jsonObject); #ifdef Q_OS_WIN32 QString fileName = QCoreApplication::applicationDirPath() + "\\config\\TriggerConfig.json"; #endif #ifdef Q_OS_LINUX QString fileName = QCoreApplication::applicationDirPath() + "/config/TriggerConfig.json"; #endif file.open(QIODevice::WriteOnly); file.write(jsonDoc.toJson()); file.close(); } QString strURL = QString("ftp://%1/CIDW/qtconfig/%2").arg(IP).arg("TriggerConfig.json"); g_FtpClient->SetServerInfo(strURL); g_FtpClient->SetUserInfo("root","@#cidw!@123456"); g_FtpClient->UpLoadFile(fileName,"TriggerConfig.json"); } QString COtherConfig::GBK2UTF8(QByteArray inStr) { QTextCodec *gbk = QTextCodec::codecForName("gbk"); QTextCodec *utf8 = QTextCodec::codecForName("UTF-8"); char *p = inStr.data(); QString str = gbk->toUnicode(p); QByteArray utf8_bytes=utf8->fromUnicode(str); p = utf8_bytes.data(); str = p; return str; } inline QString UTF82GBK(QByteArray &inStr) { QTextCodec *gbk = QTextCodec::codecForName("gbk"); QTextCodec *utf8 = QTextCodec::codecForName("UTF-8"); char *p = inStr.data(); QString str = utf8->toUnicode(p); QByteArray utf8_bytes=gbk->fromUnicode(str); p = utf8_bytes.data(); str = p; return str; } void COtherConfig::on_pushButton_main_clicked() { #ifdef Q_OS_WIN32 QSettings *settings = new QSettings(QCoreApplication::applicationDirPath() + "\\config\\config.ini", QSettings::IniFormat); #endif #ifdef Q_OS_LINUX QSettings *settings = new QSettings(QCoreApplication::applicationDirPath() + "/config/config.ini", QSettings::IniFormat); #endif settings->setIniCodec(QTextCodec::codecForName("UTF-8")); settings->setValue("main/Version", ui->textEdit_version->toPlainText()); settings->setValue("main/Project", ui->textEdit_project->toPlainText()); delete settings; QMessageBox::information(this, QStringLiteral("提示"), "保存成功!"); } void COtherConfig::slotNetMgr(QString sAddr, const QVariant &msg) { QJsonObject objec = msg.value(); if(objec.contains("cmd")) { QJsonValue arrays_value = objec.take("cmd"); qDebug()<<"cmd ="<pushButton_open_close->setEnabled("true"); bool enable = objec.take("enable").toBool(); if(enable){ ui->radioButton_open_2->setChecked(true); ui->radioButton_close_2->setChecked(false); ui->pushButton_open_close->setText("关闭"); }else{ ui->radioButton_open_2->setChecked(false); ui->radioButton_close_2->setChecked(true); ui->pushButton_open_close->setText("打开"); } get_status = false; }else if(arrays_value.toString() == "61850"){ bool Status = objec.take("success").toBool(); QString strMessage = objec.take("message").toString(); if(Status){ QMessageBox::information(this, QStringLiteral("提示"), strMessage); QString filepath = QFileDialog::getExistingDirectory(this, tr("选择文件夹"), tr("")); if(filepath == "") return; QString fileName = "SJ90C_IEC61850.icd"; g_NetMgr->RequestDownload(IP, fileName, filepath); QFileInfo file(filepath + fileName); qDebug()<comboBox_ch->currentText()){ tachometerObj["slot"] = g_ChannelBaseInfo[i].bordNo; tachometerObj["channel"] = g_ChannelBaseInfo[i].channelNoInBoard; } if(g_ChannelBaseInfo[i].channelName == ui->comboBox_ch2->currentText()){ ref_channelObj["slot"] = g_ChannelBaseInfo[i].bordNo; ref_channelObj["channel"] = g_ChannelBaseInfo[i].channelNoInBoard; } } ref_channelObj["peaktopeak"] = ui->lineEdit_peaktopeak->text().toDouble(); if(ui->comboBox_logic->currentText() == "或"){ ZeroDriftObj["logic"] = 1; }else{ ZeroDriftObj["logic"] = 0; } ZeroDriftObj["operation"] = 1; ZeroDriftObj["tachometer"] = tachometerObj; ZeroDriftObj["ref_channel"] = ref_channelObj; QJsonDocument jsonDoc; jsonDoc.setObject(ZeroDriftObj); #ifdef Q_OS_WIN32 QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ZeroDrift.json"; #endif #ifdef Q_OS_LINUX QString fileName = QCoreApplication::applicationDirPath() + "/config/ZeroDrift.json"; #endif QFile file(fileName); file.open(QIODevice::WriteOnly); file.write(jsonDoc.toJson()); file.close(); QJsonObject allObj; allObj.insert("cmd", "88"); allObj["cmdBody"] = ZeroDriftObj; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,allObj); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); } ui->comboBox_ch->setEnabled(0); ui->comboBox_ch2->setEnabled(0); ui->comboBox_logic->setEnabled(0); ui->lineEdit_peaktopeak->setEnabled(0); } void COtherConfig::on_radioButton_close_clicked() { #ifdef Q_OS_WIN32 QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ZeroDrift.json"; #endif #ifdef Q_OS_LINUX QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ZeroDrift.json"; #endif if(!fileName.isEmpty()) { qDebug() << "打开" << fileName ; QFile file(fileName); file.open(QIODevice::ReadOnly | QIODevice::Text); QString value = file.readAll(); file.close(); QJsonParseError parseJsonErr; QJsonDocument document = QJsonDocument::fromJson(value.toUtf8(), &parseJsonErr); if (!(parseJsonErr.error == QJsonParseError::NoError)) { QMessageBox::about(NULL, "提示", "读取文件错误!"); return; } QJsonObject ZeroDriftObj; ZeroDriftObj["operation"] = 0; QJsonDocument jsonDoc; jsonDoc.setObject(ZeroDriftObj); #ifdef Q_OS_WIN32 QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ZeroDrift.json"; #endif #ifdef Q_OS_LINUX QString fileName = QCoreApplication::applicationDirPath() + "\\config\\ZeroDrift.json"; #endif file.open(QIODevice::WriteOnly); file.write(jsonDoc.toJson()); file.close(); QJsonObject allObj; allObj.insert("cmd", "88"); allObj["cmdBody"] = ZeroDriftObj; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,allObj); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); } ui->comboBox_ch->setEnabled(1); ui->comboBox_ch2->setEnabled(1); ui->comboBox_logic->setEnabled(1); ui->lineEdit_peaktopeak->setEnabled(1); } void COtherConfig::on_radioButton_openIO_clicked() { bool ok; QString password = QInputDialog::getText(this, "输入密码", "Enter Password:", QLineEdit::Password, "", &ok); if(!ok) { ui->radioButton_openIO->setChecked(0); ui->radioButton_closeIO->setChecked(1); return; } #ifdef Q_OS_WIN32 QSettings settingsread(QCoreApplication::applicationDirPath() + "\\config\\config.ini",QSettings::IniFormat); #endif #ifdef Q_OS_LINUX QSettings settingsread(QCoreApplication::applicationDirPath() + "/config/config.ini",QSettings::IniFormat); #endif if(password == settingsread.value("main/passwd").toString()) { g_strIOControl = "1"; }else{ QMessageBox::information(this, QStringLiteral("提示"), "请输入正确的密码!"); } } void COtherConfig::on_radioButton_closeIO_clicked() { g_strIOControl = "0"; } void COtherConfig::on_radioButton_open_2_clicked() { } void COtherConfig::on_radioButton_close_2_clicked() { } void COtherConfig::on_pushButton_get_clicked() { QJsonObject sendData; sendData["cmd"] = "113"; sendData["subcmd"] = 0; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); get_status = true; } void COtherConfig::on_pushButton_open_close_clicked() { QMessageBox::StandardButton ret = QMessageBox::question(nullptr, "确认", "是否继续?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (ret == QMessageBox::No) { return; } QString btn_text = ui->pushButton_open_close->text(); if(btn_text == "打开"){ QJsonObject sendData; sendData["cmd"] = "113"; sendData["subcmd"] = 1; sendData["enable"] = true; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); ui->pushButton_open_close->setText("关闭"); }else if(btn_text == "关闭"){ QJsonObject sendData; sendData["cmd"] = "113"; sendData["subcmd"] = 1; sendData["enable"] = false; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); ui->pushButton_open_close->setText("打开"); } } void COtherConfig::on_pushButton_generate_clicked() { QJsonObject sendData; sendData["cmd"] = "61850"; QNetworkRequest req; QString sUrl = QString("http://%1/cgi-bin/General.cgi/").arg(IP); req.setUrl(sUrl); g_NetMgr->PostJson(req,sendData); connect(g_NetMgr,SIGNAL(sigNetMgr(QString, const QVariant&)), this, SLOT(slotNetMgr(QString,const QVariant&))); }