diff --git a/JsonTreeModel.cpp b/JsonTreeModel.cpp index c6c166b..973a406 100644 --- a/JsonTreeModel.cpp +++ b/JsonTreeModel.cpp @@ -91,6 +91,35 @@ bool JsonTreeModel::dumpJson(const QString &filepath) return true; } +bool JsonTreeModel::readJson(void) +{ + //root 的child最多也只有一个 + if(!theRootItem||theRootItem->childCount()==0) + return false; + JsonTreeItem *top_level_item=theRootItem->childItem(0); + if(!top_level_item) + return false; + + switch (top_level_item->type()) { + case JsonTreeItem::Object: + json_doc=QJsonDocument::fromVariant(dumpObject(top_level_item)); + break; + case JsonTreeItem::Array: + json_doc=QJsonDocument::fromVariant(dumpArray(top_level_item)); + break; + default: +// break; + return false; + } + + return true; +} + +// bool writeJson(QJsonDocument jsonDoc) +// { + +// } + QModelIndex JsonTreeModel::index(int row, int column, const QModelIndex &parent) const { if (!hasIndex(row, column, parent)) diff --git a/JsonTreeModel.h b/JsonTreeModel.h index f623397..cf17580 100644 --- a/JsonTreeModel.h +++ b/JsonTreeModel.h @@ -22,6 +22,13 @@ public: //导入导出数据 bool loadJson(const QString &filepath); bool dumpJson(const QString &filepath); + + + //遍历Tree生成JsonDocument + QJsonDocument json_doc; + /* qt读写配置文件的时候使用 */ + bool readJson(void); + // bool writeJson(QJsonDocument jsonDoc); //tree数据展示 QModelIndex index(int row, int column, diff --git a/chargControlBox_cfgFile.pro.user b/chargControlBox_cfgFile.pro.user index a8a2bf5..2f066be 100644 --- a/chargControlBox_cfgFile.pro.user +++ b/chargControlBox_cfgFile.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {844cf8e3-8231-4057-928d-29ec52433497} + {9e8e3043-7943-45b0-b792-c7d18b89a4a7} ProjectExplorer.Project.ActiveTarget @@ -74,17 +74,17 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.12.9 MinGW 32-bit - Desktop Qt 5.12.9 MinGW 32-bit - qt.qt5.5129.win32_mingw73_kit + Desktop Qt 5.12.9 MinGW 64-bit + Desktop Qt 5.12.9 MinGW 64-bit + qt.qt5.5129.win64_mingw73_kit 0 0 0 true 0 - D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug - D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + D:\workstudy\document\MPPT\stm32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Debug + D:/workstudy/document/MPPT/stm32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Debug true @@ -134,8 +134,8 @@ true 2 - D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Release - D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Release + D:\workstudy\document\MPPT\stm32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Release + D:/workstudy/document/MPPT/stm32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Release true @@ -185,8 +185,8 @@ true 0 - D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Profile - D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Profile + D:\workstudy\document\MPPT\stm32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Profile + D:/workstudy/document/MPPT/stm32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Profile true @@ -308,8 +308,8 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro - D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + Qt4ProjectManager.Qt4RunConfiguration:D:/workstudy/document/MPPT/stm32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + D:/workstudy/document/MPPT/stm32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro false @@ -320,7 +320,7 @@ false true - D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + D:/workstudy/document/MPPT/stm32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Debug 1 diff --git a/chargControlBox_cfgFile.pro.user.844cf8e b/chargControlBox_cfgFile.pro.user.844cf8e new file mode 100644 index 0000000..a8a2bf5 --- /dev/null +++ b/chargControlBox_cfgFile.pro.user.844cf8e @@ -0,0 +1,340 @@ + + + + + + EnvironmentId + {844cf8e3-8231-4057-928d-29ec52433497} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + Builtin.Questionable + + true + Builtin.DefaultTidyAndClazy + 8 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.9 MinGW 32-bit + Desktop Qt 5.12.9 MinGW 32-bit + qt.qt5.5129.win32_mingw73_kit + 0 + 0 + 0 + + true + 0 + D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + 2 + 2 + + + true + 2 + D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Release + D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Release + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 2 + + + true + 0 + D:\psx\MPPT\STM32\qt\build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Profile + D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + + false + + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + + false + + false + true + true + false + false + true + + D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 9ed11b1..ad615a2 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,7 +6,7 @@ #include #include #include - +#include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -24,7 +24,6 @@ MainWindow::~MainWindow() void MainWindow::openFile() { - static QString loadpath; if (ui->openFile->text() == "打开文件") { //选择导入的文件路径 loadpath = QFileDialog::getOpenFileName(this,"选择文件","/", "Files(*.json)"); @@ -99,6 +98,25 @@ void MainWindow::Init() } +uint16_t MainWindow::modbusCrc(uint8_t *arr_buff, uint8_t len) +{ + uint16_t crc=0xFFFF; + uint16_t i, j; + + for ( j=0; j0){ + crc=crc>>1; + crc=crc^ 0xa001; + }else{ + crc=crc>>1; + } + } + } + return crc; +} + void MainWindow::openSerialPortPushButtonClicked() { if (ui->SerialPortPushButton->text() == "打开串口") { @@ -209,10 +227,2158 @@ void MainWindow::openSerialPortPushButtonClicked() void MainWindow::readCfgFile() { qDebug(" in readCfgFile "); + + uint8_t readCfgBuf[256]; + uint8_t *readCfgPoint = readCfgBuf; + + /* 起始标志 */ + *readCfgPoint = 'S'; + readCfgPoint += 1; + *readCfgPoint = 'L'; + readCfgPoint += 1; + + /* 唯一ID */ +// QJsonDocument json_doc; + + // 判断是否解析失败 +// if (jsonModel->readJson() != true || !json_doc.isNull()) { +// if (!jsonModel->readJson() || !jsonModel->json_doc.isNull()) { +// qDebug() << "Json格式错误!" ; +// return; +// } + + + /* 唯一ID */ + bool flag = jsonModel->readJson(); + if (!flag) { + qDebug() << "Json格式错误1!" ; + return; + } + + if (jsonModel->json_doc.isNull()) { + qDebug() << "Json格式错误2!" ; + return; + } + + /* 获取根 { } */ +// QJsonObject rootObj = json_doc.object(); + + if (!jsonModel->json_doc.isObject()) { + qDebug() << "json_doc.isObject()" ; + } + + QJsonValue tempValue = jsonModel->json_doc.object().value("充电控制盒配置文件"); +// QJsonValue tempValue = rootObj.value("充电控制盒配置文件"); +// QJsonValue tempValue = rootObj.value("chargeControlCfgFile"); + QJsonObject tempObject; + QJsonObject rootObj; + if (tempValue.isObject()) { + rootObj = tempValue.toObject(); + } + else { + qDebug() << "充电控制盒配置文件 error" << tempValue.type() ; + return; + } + + + tempValue = rootObj.value("设备的唯一地址"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "onlyID object error" << tempValue.type() ; + return; + } + + tempValue = tempObject.value("unique_Device_ID"); + QJsonArray tempArray; + if (tempValue.isArray()) { + tempArray = tempValue.toArray(); + } + else { + qDebug() << "onlyID object error" << tempValue.type() ; + return; + } + + QString tempString = tempArray.at(0).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) + bool ok; + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; +// readCfgBuf[2] = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(1).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[3] = tempString.toInt(&ok, 16); + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(2).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[4] = tempString.toInt(&ok, 16); + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(3).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[5] = tempString.toInt(&ok, 16); + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(4).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[6] = tempString.toInt(&ok, 16); + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(5).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[7] = tempString.toInt(&ok, 16); + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(6).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[8] = tempString.toInt(&ok, 16); + *readCfgPoint = tempString.toInt(&ok, 16); + readCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + +// qDebug(" 0x%x ", readCfgBuf[0]); +// qDebug(" 0x%x ", readCfgBuf[1]); +// qDebug(" 0x%x ", readCfgBuf[2]); +// qDebug(" 0x%x ", readCfgBuf[3]); +// qDebug(" 0x%x ", readCfgBuf[4]); +// qDebug(" 0x%x ", readCfgBuf[5]); +// qDebug(" 0x%x ", readCfgBuf[6]); +// qDebug(" 0x%x ", readCfgBuf[7]); +// qDebug(" 0x%x ", readCfgBuf[8]); + /* 功能码 */ +// readCfgBuf[9] = 0xD1; + *readCfgPoint = 0xD1; + readCfgPoint += 1; + + /* 数据长度 */ + *readCfgPoint = 29 >> 8; + readCfgPoint += 1; + *readCfgPoint = 29; + readCfgPoint += 1; + + /* 数据内容 */ + *readCfgPoint = (uint8_t)(0x0000 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0000; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0001 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0001; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0002 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0002; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0100 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0100; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0101 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0101; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0102 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0102; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0103 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0103; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0104 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0104; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0105 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0105; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0106 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0106; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0107 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0107; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0108 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0108; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0109 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0109; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x010A >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x010A; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x010B >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x010B; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x010C >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x010C; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x010D >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x010D; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x010E >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x010E; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x010F >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x010F; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0110 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0110; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0111 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0111; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0112 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0112; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0113 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0113; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0114 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0114; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0115 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0115; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0116 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0116; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0117 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0117; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0118 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0118; + readCfgPoint += 1; + + *readCfgPoint = (uint8_t)(0x0119 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)0x0119; + readCfgPoint += 1; + + /* crc校验 */ + uint16_t tempU16 = 0; + tempU16 = modbusCrc(readCfgBuf, (29 * 2 + 12)); + *readCfgPoint = (uint8_t)(tempU16 >> 8); + readCfgPoint += 1; + *readCfgPoint = (uint8_t)tempU16; + readCfgPoint += 1; + + /* 结束标志 */ + *readCfgPoint = 0x16; + +// for (int i = 0; i < 29 * 2 + 12 + 3; i++) { +// qDebug(" 0x%x ", readCfgBuf[i]); +// } + +// /* 设备的唯一地址 */ +// tempValue = rootObj.value("设备的唯一地址"); +// if (tempValue.isObject()) { +// tempObject = tempValue.toObject(); +// } +// else { +// qDebug() << "设备的唯一地址 error" << tempValue.type() ; +// return; +// } +// tempValue = tempObject.value("类型"); +// if (tempValue.isString()) { +// tempString = tempValue.toString(); +// } +// else { +// qDebug() << "设备的唯一地址 error" << tempValue.type() ; +// return; +// } +// tempString.remove("H"); +// // 将字符串转换为整数(基数为 16) +//// readCfgBuf[11] = tempString.toInt(&ok, 16); +// *readCfgPoint = tempString.toInt(&ok, 16); +// readCfgPoint += 1; +// if (!ok) { +// qDebug() << "转换失败!"; +// return; +// } +// readCfgBuf[10] = 0; +// readCfgBuf[10]++; +//// qDebug(" 0x%x ", readCfgBuf[11]); + +// /* 对上通讯波特率 */ +// tempValue = rootObj.value("SL协议对上通信波特率"); +// if (tempValue.isObject()) { +// tempObject = tempValue.toObject(); +// } +// else { +// qDebug() << "SL协议对上通信波特率error" << tempValue.type() ; +// return; +// } +// tempValue = tempObject.value("类型"); +// if (tempValue.isString()) { +// tempString = tempValue.toString(); +// } +// else { +// qDebug() << "SL协议对上通信波特率类型 error" << tempValue.type() ; +// return; +// } +// tempString.remove("H"); +// // 将字符串转换为整数(基数为 16) +// readCfgBuf[11] = tempString.toInt(&ok, 16); +// if (!ok) { +// qDebug() << "转换失败!"; +// return; +// } +// readCfgBuf[10]++; +//// qDebug(" 0x%x ", readCfgBuf[11]); + +// /* SL协议对下通信波特率 */ +// tempValue = rootObj.value("SL协议对下通信波特率"); +// if (tempValue.isObject()) { +// tempObject = tempValue.toObject(); +// } +// else { +// qDebug() << "SL协议对下通信波特率 error" << tempValue.type() ; +// return; +// } +// tempValue = tempObject.value("类型"); +// if (tempValue.isString()) { +// tempString = tempValue.toString(); +// } +// else { +// qDebug() << "SL协议对下通信波特率 error" << tempValue.type() ; +// return; +// } +// tempString.remove("H"); +// // 将字符串转换为整数(基数为 16) +// readCfgBuf[11] = tempString.toInt(&ok, 16); +// if (!ok) { +// qDebug() << "转换失败!"; +// return; +// } +// readCfgBuf[10]++; + + ui->SerialPortPushButton->setEnabled(false); + ui->readConfigFile->setEnabled(false); + ui->writeConfigFile->setEnabled(false); + + serialPort->write(reinterpret_cast(readCfgBuf), (29 * 2 + 12 + 3)); + +// /* 延时1.5S */ +// QThread::msleep(1500); +// QByteArray data = serialPort->readAll(); + +// /* 起始标志 */ +// if (data.at(0) != 'S' || data.at(1) != 'L') { +// goto error; +// } + +// if (data.at(0) != 'S' || data.at(1) != 'L') { +// goto error; +// } + + + +//error: + ui->SerialPortPushButton->setEnabled(true); + ui->readConfigFile->setEnabled(true); + ui->writeConfigFile->setEnabled(true); + + } void MainWindow::writeCfgFile() { qDebug(" in writeCfgFile "); + uint8_t writeCfgBuf[256]; + uint8_t *writeCfgPoint = writeCfgBuf; + + /* 起始标志 */ + *writeCfgPoint = 'S'; + writeCfgPoint += 1; + *writeCfgPoint = 'L'; + writeCfgPoint += 1; + + /* 唯一ID */ +// QJsonDocument json_doc; + + // 判断是否解析失败 +// if (jsonModel->readJson() != true || !json_doc.isNull()) { +// if (!jsonModel->readJson() || !jsonModel->json_doc.isNull()) { +// qDebug() << "Json格式错误!" ; +// return; +// } + + + /* 唯一ID */ + bool flag = jsonModel->readJson(); + if (!flag) { + qDebug() << "Json格式错误1!" ; + return; + } + + if (jsonModel->json_doc.isNull()) { + qDebug() << "Json格式错误2!" ; + return; + } + + /* 获取根 { } */ +// QJsonObject rootObj = json_doc.object(); + + if (!jsonModel->json_doc.isObject()) { + qDebug() << "json_doc.isObject()" ; + } + + QJsonValue tempValue = jsonModel->json_doc.object().value("充电控制盒配置文件"); +// QJsonValue tempValue = rootObj.value("充电控制盒配置文件"); +// QJsonValue tempValue = rootObj.value("chargeControlCfgFile"); + QJsonObject tempObject; + QJsonObject rootObj; + if (tempValue.isObject()) { + rootObj = tempValue.toObject(); + } + else { + qDebug() << "充电控制盒配置文件 error" << tempValue.type() ; + return; + } + + + tempValue = rootObj.value("设备的唯一地址"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "onlyID object error" << tempValue.type() ; + return; + } + + tempValue = tempObject.value("unique_Device_ID"); + QJsonArray tempArray; + if (tempValue.isArray()) { + tempArray = tempValue.toArray(); + } + else { + qDebug() << "onlyID object error" << tempValue.type() ; + return; + } + + QString tempString = tempArray.at(0).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) + bool ok; + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; +// readCfgBuf[2] = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(1).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[3] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(2).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[4] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(3).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[5] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(4).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[6] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(5).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[7] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(6).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[8] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + /* 功能码 */ + *writeCfgPoint = 0xD0; + writeCfgPoint += 1; + + /* 帧编号 */ + *writeCfgPoint = 1; + writeCfgPoint += 1; + + /* 总帧数 */ + *writeCfgPoint = 1; + writeCfgPoint += 1; + + + /* 数据长度 */ + uint16_t dataLen = 0; + writeCfgPoint += 2; + + /* 数据内容 */ + /* 更改设备的唯一地址 */ + tempValue = rootObj.value("更改设备的唯一地址"); + /* + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; + return; + }*/ + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + uint16_t tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("更改设备的唯一地址"); + tempValue = tempObject.value("unique_Device_ID"); + if (tempValue.isArray()) { + tempArray = tempValue.toArray(); + } + else { + qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; + return; + } + + tempString = tempArray.at(0).toString(); + tempString.remove("0x"); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(1).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[3] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(2).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[4] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(3).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[5] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(4).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[6] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(5).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[7] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + + tempString = tempArray.at(6).toString(); + tempString.remove("0x"); + // 将字符串转换为整数(基数为 16) +// readCfgBuf[8] = tempString.toInt(&ok, 16); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + if (!ok) { + qDebug() << "转换失败!"; + return; + } + dataLen += 7; + + /* SL协议对上通信波特率 */ + tempValue = rootObj.value("SL协议对上通信波特率"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "SL协议对上通信波特率 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "更改设备的唯一地址 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("SL协议对上通信波特率"); + tempValue = tempObject.value("SL_Protocol_Communication_Baud_Rate_Up"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "SL_Protocol_Communication_Baud_Rate_Up error" << tempValue.type() ; + return; + } + tempString.remove("0x"); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + dataLen += 1; + + /* SL协议对下通信波特率 */ + tempValue = rootObj.value("SL协议对下通信波特率"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "SL协议对下通信波特率 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("SL协议对下通信波特率"); + tempValue = tempObject.value("SL_Protocol_Communication_Baud_Rate_Down"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "SL_Protocol_Communication_Baud_Rate_Down error" << tempValue.type() ; + return; + } + tempString.remove("0x"); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + dataLen += 1; + + /* 电源盒类型 */ + tempValue = rootObj.value("电源盒类型"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "电源盒类型 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("电源盒类型"); + tempValue = tempObject.value("power_Box_Type"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "power_Box_Type error" << tempValue.type() ; + return; + } + tempString.remove("0x"); + *writeCfgPoint = tempString.toInt(&ok, 16); + writeCfgPoint += 1; + dataLen += 1; + + /* 恒压充电阈值电压 */ + tempValue = rootObj.value("恒压充电阈值电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "恒压充电阈值电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("恒压充电阈值电压"); + tempValue = tempObject.value("constant_Voltage_V"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "constant_Voltage_V error" << tempValue.type() ; + return; + } + float tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 浮充充电阈值电流 */ + tempValue = rootObj.value("浮充充电阈值电流"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "浮充充电阈值电流 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("浮充充电阈值电流"); + tempValue = tempObject.value("float_I"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "float_I error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 启动充电太阳能板开路电压 */ + tempValue = rootObj.value("启动充电太阳能板开路电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "启动充电太阳能板开路电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("启动充电太阳能板开路电压"); + tempValue = tempObject.value("start_Solar_Open_Circuit_V"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "start_Solar_Open_Circuit_V error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 停止充电太阳能板输出电压 */ + tempValue = rootObj.value("停止充电太阳能板输出电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "停止充电太阳能板输出电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("停止充电太阳能板输出电压"); + tempValue = tempObject.value("stop_Solar_Output_Circuit_V"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "stop_Solar_Output_Circuit_V error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 启动时开路电压检测间隔 */ + tempValue = rootObj.value("启动时开路电压检测间隔"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "启动时开路电压检测间隔 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("启动时开路电压检测间隔"); + tempValue = tempObject.value("check_Can_Start_Time"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "check_Can_Start_Time error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 短路判断延时 */ + tempValue = rootObj.value("短路判断延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "短路判断延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("短路判断延时"); + tempValue = tempObject.value("short_Circuit_Judgment_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "short_Circuit_Judgment_Delay error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 前端输入功率不足判断延时 */ + tempValue = rootObj.value("前端输入功率不足判断延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "前端输入功率不足判断延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("前端输入功率不足判断延时"); + tempValue = tempObject.value("input_Power_Low_Judgment_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "input_Power_Low_Judgment_Delay error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 前端输入功率不足后再次输出延时 */ + tempValue = rootObj.value("前端输入功率不足后再次输出延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "前端输入功率不足后再次输出延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("前端输入功率不足后再次输出延时"); + tempValue = tempObject.value("input_Power_Low_Again_Output_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "input_Power_Low_Again_Output_Delay error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 第一段保护延时 */ + tempValue = rootObj.value("第一段保护延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "第一段保护延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("第一段保护延时"); + tempValue = tempObject.value("first_Stage_Protection_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "first_Stage_Protection_Delay error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 第一段保护的电流 */ + tempValue = rootObj.value("第一段保护的电流"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "第一段保护的电流 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("第一段保护的电流"); + tempValue = tempObject.value("first_Stage_Protection_Curr"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "first_Stage_Protection_Curr error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 第二段保护延时 */ + tempValue = rootObj.value("第二段保护延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "第二段保护延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("第二段保护延时"); + tempValue = tempObject.value("second_Stage_Protection_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "second_Stage_Protection_Delay error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 第二段保护的电流 */ + tempValue = rootObj.value("第二段保护的电流"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "第二段保护的电流 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("第二段保护的电流"); + tempValue = tempObject.value("second_Stage_Protection_Curr"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "second_Stage_Protection_Curr error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 第三段保护延时 */ + tempValue = rootObj.value("第三段保护延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "第三段保护延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("第三段保护延时"); + tempValue = tempObject.value("third_Stage_Protection_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "third_Stage_Protection_Delay error" << tempValue.type() ; + return; + } + uint32_t tempU32 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU32 >> 24); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)(tempU32 >> 16); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)(tempU32 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU32; + writeCfgPoint += 1; + dataLen += 4; + + /* 第三段保护的电流 */ + tempValue = rootObj.value("第三段保护的电流"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "第三段保护的电流 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("第三段保护的电流"); + tempValue = tempObject.value("third_Stage_Protection_Curr"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "third_Stage_Protection_Curr error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 前端输入功率不足检测延时 */ + tempValue = rootObj.value("前端输入功率不足检测延时"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "前端输入功率不足检测延时 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("前端输入功率不足检测延时"); + tempValue = tempObject.value("input_Power_Low_Detection_Delay"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "input_Power_Low_Detection_Delay error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 前端输入功率不足检测电压 */ + tempValue = rootObj.value("前端输入功率不足检测电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "前端输入功率不足检测电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("前端输入功率不足检测电压"); + tempValue = tempObject.value("input_Power_Low_Detection_Volt"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "input_Power_Low_Detection_Volt error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 最大太阳能板输出电压 */ + tempValue = rootObj.value("最大太阳能板输出电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "最大太阳能板输出电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("最大太阳能板输出电压"); + tempValue = tempObject.value("max_Open_Solar_Output_Circuit_V"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "max_Open_Solar_Output_Circuit_V error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 最大充电电流 */ + tempValue = rootObj.value("最大充电电流"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "最大充电电流 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("最大充电电流"); + tempValue = tempObject.value("max_Charg_Curr"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "max_Charg_Curr error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 检测回路阻抗时的最小充电电流 */ + tempValue = rootObj.value("检测回路阻抗时的最小充电电流"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "检测回路阻抗时的最小充电电流 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("检测回路阻抗时的最小充电电流"); + tempValue = tempObject.value("min_Check_Loop_Impedance_Charg_Curr"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "min_Check_Loop_Impedance_Charg_Curr error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 全功率输出温度 */ + tempValue = rootObj.value("全功率输出温度"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "全功率输出温度 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("全功率输出温度"); + tempValue = tempObject.value("full_Power_Output_Temperature"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "full_Power_Output_Temperature error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 降功率输出温度 */ + tempValue = rootObj.value("降功率输出温度"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "降功率输出温度 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("降功率输出温度"); + tempValue = tempObject.value("reduce_Power_Output_Temperature"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "reduce_Power_Output_Temperature error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 停止输出温度 */ + tempValue = rootObj.value("停止输出温度"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "停止输出温度 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("停止输出温度"); + tempValue = tempObject.value("stop_PowerOutput_Temperature"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "stop_PowerOutput_Temperature error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + + /* 恒压充电时的输出电压 */ + tempValue = rootObj.value("恒压充电时的输出电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "恒压充电时的输出电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("恒压充电时的输出电压"); + tempValue = tempObject.value("constant_Voltage_Charge_V"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "constant_Voltage_Charge_V error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 浮充充电时的输出电压 */ + tempValue = rootObj.value("浮充充电时的输出电压"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "浮充充电时的输出电压 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("浮充充电时的输出电压"); + tempValue = tempObject.value("float_ChargeV"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "float_ChargeV error" << tempValue.type() ; + return; + } + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + tempU16 = tempFloat * 10; + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 充电时开路电压采集间隔 */ + tempValue = rootObj.value("充电时开路电压采集间隔"); + if (tempValue.isObject()) { + tempObject = tempValue.toObject(); + } + else { + qDebug() << "充电时开路电压采集间隔 error" << tempValue.type() ; + return; + } + tempValue = tempObject.value("类型"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "类型 error" << tempValue.type() ; + return; + } + tempString.remove("H"); + // 将字符串转换为整数(基数为 16) + tempU16 = tempString.toInt(&ok, 16); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + tempValue = rootObj.value("充电时开路电压采集间隔"); + tempValue = tempObject.value("collect_OpenCircuit_Voltage_Time"); + if (tempValue.isString()) { + tempString = tempValue.toString(); + } + else { + qDebug() << "collect_OpenCircuit_Voltage_Time error" << tempValue.type() ; + return; + } + tempU16 = tempString.toInt(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + dataLen += 2; + + /* 数据长度 */ + writeCfgBuf[12] = (uint8_t)(dataLen >> 8); + writeCfgBuf[13] = (uint8_t)dataLen; + + /* modbusCrc校验 */ + tempU16 = modbusCrc(writeCfgBuf, dataLen + 14); + *writeCfgPoint = (uint8_t)(tempU16 >> 8); + writeCfgPoint += 1; + *writeCfgPoint = (uint8_t)tempU16; + writeCfgPoint += 1; + + *writeCfgPoint = 0x16; + +// for (int i = 0; i < dataLen + 17; i++) { +// qDebug(" 0x%x ", writeCfgBuf[i]); +// } + + serialPort->write(reinterpret_cast(writeCfgBuf), (dataLen + 17)); } diff --git a/mainwindow.h b/mainwindow.h index b9d9c04..b3cf48a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -32,6 +32,8 @@ private: JsonTreeModel *jsonModel; + QString loadpath; + bool openSerialPortFlag; bool openFileFlag; @@ -39,6 +41,8 @@ private: void scanSerialPort(); void parityItemInit(); + uint16_t modbusCrc(uint8_t *arr_buff, uint8_t len); + private slots: void openFile(); void openSerialPortPushButtonClicked(); diff --git a/mainwindow.ui b/mainwindow.ui index a433b98..d501dae 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -6,8 +6,8 @@ 0 0 - 834 - 666 + 995 + 750 @@ -19,8 +19,8 @@ 10 10 - 821 - 611 + 971 + 691 @@ -103,8 +103,7 @@ - - + 串口 @@ -468,7 +467,7 @@ 0 0 - 834 + 995 23