diff --git a/JsonTreeModel.cpp b/JsonTreeModel.cpp index 973a406..31936c7 100644 --- a/JsonTreeModel.cpp +++ b/JsonTreeModel.cpp @@ -120,6 +120,23 @@ bool JsonTreeModel::readJson(void) // } +void JsonTreeModel::refreshJson(void) +{ + emit beginResetModel(); + theRootItem->deleteAllChild();//清空之前的model + + //判断是object{}还是array[]的Json + if(json_doc.isObject()){ + //解析文档中的Object + parseObject("[Root]",json_doc.object(),theRootItem); + }else if(json_doc.isArray()){ + //解析文档中的Array + parseArray("[Root]",json_doc.array(),theRootItem); + } + + emit endResetModel(); +} + 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 cf17580..9f477f9 100644 --- a/JsonTreeModel.h +++ b/JsonTreeModel.h @@ -29,6 +29,7 @@ public: /* qt读写配置文件的时候使用 */ bool readJson(void); // bool writeJson(QJsonDocument jsonDoc); + void refreshJson(void); //tree数据展示 QModelIndex index(int row, int column, diff --git a/chargControlBox_cfgFile.pro.user b/chargControlBox_cfgFile.pro.user index 2f066be..1c08574 100644 --- a/chargControlBox_cfgFile.pro.user +++ b/chargControlBox_cfgFile.pro.user @@ -1,10 +1,10 @@ - + EnvironmentId - {9e8e3043-7943-45b0-b792-c7d18b89a4a7} + {844cf8e3-8231-4057-928d-29ec52433497} ProjectExplorer.Project.ActiveTarget @@ -74,17 +74,17 @@ ProjectExplorer.Project.Target.0 - Desktop Qt 5.12.9 MinGW 64-bit - Desktop Qt 5.12.9 MinGW 64-bit - qt.qt5.5129.win64_mingw73_kit + 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:\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 + 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 @@ -134,8 +134,8 @@ true 2 - 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 + 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 @@ -185,8 +185,8 @@ true 0 - 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 + 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 @@ -308,8 +308,8 @@ 2 - Qt4ProjectManager.Qt4RunConfiguration:D:/workstudy/document/MPPT/stm32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro - D:/workstudy/document/MPPT/stm32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + Qt4ProjectManager.Qt4RunConfiguration:D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + D:/psx/MPPT/STM32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro false @@ -320,7 +320,7 @@ false true - D:/workstudy/document/MPPT/stm32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Debug + D:/psx/MPPT/STM32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_32_bit-Debug 1 diff --git a/chargControlBox_cfgFile.pro.user.9e8e304 b/chargControlBox_cfgFile.pro.user.9e8e304 new file mode 100644 index 0000000..2f066be --- /dev/null +++ b/chargControlBox_cfgFile.pro.user.9e8e304 @@ -0,0 +1,340 @@ + + + + + + EnvironmentId + {9e8e3043-7943-45b0-b792-c7d18b89a4a7} + + + 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 64-bit + Desktop Qt 5.12.9 MinGW 64-bit + qt.qt5.5129.win64_mingw73_kit + 0 + 0 + 0 + + true + 0 + 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 + 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:\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 + 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:\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 + 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:/workstudy/document/MPPT/stm32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + D:/workstudy/document/MPPT/stm32/qt/chargControlBox_cfgFile/chargControlBox_cfgFile.pro + + false + + false + true + true + false + false + true + + D:/workstudy/document/MPPT/stm32/qt/build-chargControlBox_cfgFile-Desktop_Qt_5_12_9_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/mainwindow.cpp b/mainwindow.cpp index f42bf7d..25a194d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -7,6 +7,9 @@ #include #include #include +#include + + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) @@ -647,45 +650,134 @@ void MainWindow::readCfgFile() // } // readCfgBuf[10]++; - ui->SerialPortPushButton->setDisabled(true); - ui->readConfigFile->setDisabled(true); - ui->writeConfigFile->setDisabled(true); +// ui->SerialPortPushButton->setDisabled(true); +// ui->readConfigFile->setDisabled(true); +// ui->writeConfigFile->setDisabled(true); serialPort->write(reinterpret_cast(readCfgBuf), (60 + 12 + 3)); - /* 延时1.5S */ - QThread::msleep(1500); - QByteArray data = serialPort->readAll(); + QTimer::singleShot(1500, [this]() { + QByteArray data = serialPort->readAll(); +// serialPort->write("hello world"); + for (int i = 0; i < data.length(); i++) { + qDebug() << QString::asprintf("0x%x", static_cast(data.at(i))); + } + + uint16_t crc16; + uint8_t *repData = (uint8_t *)data.data(); + uint16_t tempU16; + uint8_t *analysisCfgData = repData + 12; + + /* 起始标志 */ + if (*repData != 'S' || *(repData + 1) != 'L') { + qDebug() << "start flag error"; + goto error; + } + + /* 功能码 */ + if (*(repData + 9) != 0xD1) { + qDebug() << "function Code error"; + goto error; + } + + tempU16 = (*(repData + 10) << 8) | (*(repData + 11)); + qDebug() << "len" << tempU16; + crc16 = (*(repData + 12 + tempU16) << 8) | (*(repData + 13 + tempU16)); + + /* crc校验 */ + if (crc16 != modbusCrc(repData, tempU16 + 12)) { + qDebug() << "crc error"; + qDebug() << QString::asprintf("0x%x", static_cast(crc16)); + qDebug() << QString::asprintf("0x%x", static_cast(modbusCrc(repData, tempU16 + 12))); + goto error; + } + + /* 结束标志 */ + if (*(repData + 14 + tempU16) != 0x16) { + qDebug() << "end flag error"; + goto error; + } + + while (analysisCfgData != NULL && analysisCfgData != (repData + 12 + tempU16)) { + analysisCfgData = analysisReadCfgData(&analysisCfgData); + } + if (analysisCfgData != (repData + 12 + tempU16)) { + qDebug() << "analysisCfgData error"; + goto error; + } + + jsonModel->refreshJson(); + + QMessageBox::information(this, + tr("配置文件"), + tr("读取配置文件成功"), + QMessageBox::Ok, + QMessageBox::Ok); + // reply = QMessageBox::information(this, "写入成功", + return; + + error: + QMessageBox::information(this, + tr("配置文件"), + tr("读取配置文件失败"), + QMessageBox::Ok, + QMessageBox::Ok); + + }); + +// /* 延时1.5S */ +// QThread::msleep(1500); +// QByteArray data = serialPort->readAll(); + +// ui->SerialPortPushButton->setEnabled(true); +// ui->readConfigFile->setEnabled(true); +// ui->writeConfigFile->setEnabled(true); + +// uint16_t crc16; +// uint8_t *repData = (uint8_t *)data.data(); +//// QMessageBox::standardButton reply; // if (data.length() < 17) { // goto error; // } - /* 起始标志 */ - uint8_t *repData = (uint8_t *)data.data(); - if (*repData != 'S' || *(repData + 1) != 'L') { - goto error; - } - -// /* 地址 */ -// if (data.at(0) != 'S' || data.at(1) != 'L') { +// /* 起始标志 */ +// if (*repData != 'S' || *(repData + 1) != 'L') { // goto error; // } - if (*(repData + 9) != 0xD0) { - goto error; - } +//// /* 地址 */ +//// if (data.at(0) != 'S' || data.at(1) != 'L') { +//// goto error; +//// } -// uint16_t crc16 = modbusCrc(repData, 14); +// if (*(repData + 9) != 0xD0) { +// goto error; +// } +// crc16 = (*(repData + 14) << 8) | *(repData + 15); +// if (crc16 != modbusCrc(repData, 14)) { +// goto error; +// } +// if (*(repData + 12) != 0xAA) { +// goto error; +// } + +// QMessageBox::information(this, +// tr("Information消息框标题"), +// tr("这是Information消息框的内容。"), +// QMessageBox::Ok | QMessageBox::Cancel, +// QMessageBox::Ok); +//// reply = QMessageBox::information(this, "写入成功", // return; -error: - ui->SerialPortPushButton->setEnabled(true); - ui->readConfigFile->setEnabled(true); - ui->writeConfigFile->setEnabled(true); - +//error: +// QMessageBox::information(this, +// tr("Information消息框标题error"), +// tr("这是Information消息框的内容error。"), +// QMessageBox::Ok | QMessageBox::Cancel, +// QMessageBox::Ok); } @@ -2399,4 +2491,595 @@ void MainWindow::writeCfgFile() // } serialPort->write(reinterpret_cast(writeCfgBuf), (dataLen + 17)); + + QTimer::singleShot(1500, [this]() { + QByteArray data = serialPort->readAll(); +// serialPort->write("hello world"); + for (int i = 0; i < data.length(); i++) { + qDebug() << QString::asprintf("0x%x", static_cast(data.at(i))); + } + uint16_t crc16; + uint8_t *repData = (uint8_t *)data.data(); + // QMessageBox::standardButton reply; + + if (data.length() < 16) { + qDebug() << "len is error"; + goto error; + } + + /* 起始标志 */ + if (*repData != 'S' || *(repData + 1) != 'L') { + qDebug() << "start flag error"; + goto error; + } + + // /* 地址 */ + // if (data.at(0) != 'S' || data.at(1) != 'L') { + // goto error; + // } + + if (*(repData + 9) != 0xD0) { + qDebug() << "function code error"; + goto error; + } + + crc16 = (*(repData + 13) << 8) | *(repData + 14); + if (crc16 != modbusCrc(repData, 13)) { + qDebug() << "crc error"; + goto error; + } + + if (*(repData + 12) != 0xAA) { + qDebug() << "data error"; + goto error; + } + + QMessageBox::information(this, + tr("配置文件"), + tr("写入配置文件成功"), + QMessageBox::Ok, + QMessageBox::Ok); + // reply = QMessageBox::information(this, "写入成功", + return; + + error: + QMessageBox::information(this, + tr("配置文件"), + tr("写入配置文件失败"), + QMessageBox::Ok, + QMessageBox::Ok); + + }); + + +// /* 延时1.5S */ +// QThread::msleep(1500); +// QByteArray data = serialPort->readAll(); + + +// serialPort->write("hello world"); + +//// ui->SerialPortPushButton->setEnabled(true); +//// ui->readConfigFile->setEnabled(true); +//// ui->writeConfigFile->setEnabled(true); +// for (int i = 0; i < data.length(); i++) { +// qDebug() << QString::asprintf("0x%x", data.at(i)); +// } + + +// uint16_t crc16; +// uint8_t *repData = (uint8_t *)data.data(); +//// QMessageBox::standardButton reply; + +// if (data.length() < 17) { +// goto error; +// } + +// /* 起始标志 */ +// if (*repData != 'S' || *(repData + 1) != 'L') { +// goto error; +// } + +//// /* 地址 */ +//// if (data.at(0) != 'S' || data.at(1) != 'L') { +//// goto error; +//// } + +// if (*(repData + 9) != 0xD0) { +// goto error; +// } + +// crc16 = (*(repData + 14) << 8) | *(repData + 15); +// if (crc16 != modbusCrc(repData, 14)) { +// goto error; +// } + +// if (*(repData + 12) != 0xAA) { +// goto error; +// } + +// QMessageBox::information(this, +// tr("配置文件"), +// tr("写入配置文件成功"), +// QMessageBox::Ok, +// QMessageBox::Ok); +//// reply = QMessageBox::information(this, "写入成功", +// return; + +//error: +// QMessageBox::information(this, +// tr("配置文件"), +// tr("写入配置文件失败"), +// QMessageBox::Ok, +// QMessageBox::Ok); +} + +uint8_t *MainWindow::analysisReadCfgData(uint8_t **cfgData) +{ + QJsonValue tempValue = jsonModel->json_doc.object().value("充电控制盒配置文件"); + QJsonObject rootObj; + QJsonObject tempObject; + rootObj = tempValue.toObject(); + + uint16_t dataType; + dataType = (**cfgData << 8) | *(*cfgData + 1); + + /* 唯一ID */ + if (dataType == 0x0000) { + tempValue = rootObj.value("更改设备的唯一地址"); + tempObject = tempValue.toObject(); + tempValue = tempObject.value("unique_Device_ID"); + + QJsonArray tempArray = tempValue.toArray(); + +// tempArray.replace(0, QString::asprintf("0x%x", (*(*cfgData + 2)))); +// tempArray.replace(1, QString::asprintf("0x%x", (*(*cfgData + 3)))); +// tempArray.replace(2, QString::asprintf("0x%x", (*(*cfgData + 4)))); +// tempArray.replace(3, QString::asprintf("0x%x", (*(*cfgData + 5)))); +// tempArray.replace(4, QString::asprintf("0x%x", (*(*cfgData + 6)))); +// tempArray.replace(5, QString::asprintf("0x%x", (*(*cfgData + 7)))); +// tempArray.replace(6, QString::asprintf("0x%x", (*(*cfgData + 8)))); + +// tempObject["unique_Device_ID"] = tempArray; + + return (*cfgData + 9); + } + + /* 对上通信波特率 */ + if (dataType == 0x0001) { + tempValue = rootObj.value("SL协议对上通信波特率"); + tempObject = tempValue.toObject(); + + tempObject["SL_Protocol_Communication_Baud_Rate_Up"] = QString::asprintf("0x%x", (*(*cfgData + 2))); +// tempObject["SL_Protocol_Communication_Baud_Rate_Up"] = "0x03"; + + rootObj["SL协议对上通信波特率"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 3); + } + + /* 对下通信波特率 */ + if (dataType == 0x0002) { + tempValue = rootObj.value("SL协议对下通信波特率"); + tempObject = tempValue.toObject(); + + tempObject["SL_Protocol_Communication_Baud_Rate_Down"] = QString::asprintf("0x%x", (*(*cfgData + 2))); + + rootObj["SL协议对下通信波特率"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 3); + } + + /* 电源盒类型 */ + if (dataType == 0x0100) { + tempValue = rootObj.value("电源盒类型"); + tempObject = tempValue.toObject(); + tempObject["power_Box_Type"] = QString::asprintf("0x%x", (*(*cfgData + 2))); + + rootObj["电源盒类型"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 3); + } + + /* 恒压充电阈值电压 */ + if (dataType == 0x0101) { + tempValue = rootObj.value("恒压充电阈值电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2)) | (*(*cfgData + 3))) / 10.0f; + tempObject["constant_Voltage_V"] = tempF; + + rootObj["恒压充电阈值电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 浮充充电阈值电流 */ + if (dataType == 0x0102) { + tempValue = rootObj.value("浮充充电阈值电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["float_I"] = tempF; + + rootObj["浮充充电阈值电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 启动充电太阳能板开路电压 */ + if (dataType == 0x0103) { + tempValue = rootObj.value("启动充电太阳能板开路电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["start_Solar_Open_Circuit_V"] = tempF; + + rootObj["启动充电太阳能板开路电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 停止充电太阳能板输出电压 */ + if (dataType == 0x0104) { + tempValue = rootObj.value("停止充电太阳能板输出电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["stop_Solar_Output_Circuit_V"] = tempF; + + rootObj["停止充电太阳能板输出电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 启动时开路电压检测间隔 */ + if (dataType == 0x0105) { + tempValue = rootObj.value("启动时开路电压检测间隔"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["check_Can_Start_Time"] = tempU16; + + rootObj["启动时开路电压检测间隔"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 短路判断延时 */ + if (dataType == 0x0106) { + tempValue = rootObj.value("短路判断延时"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["short_Circuit_Judgment_Delay"] = tempU16; + + rootObj["短路判断延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 前端输入功率不足判断延时 */ + if (dataType == 0x0107) { + tempValue = rootObj.value("前端输入功率不足判断延时"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["input_Power_Low_Judgment_Delay"] = tempU16; + + rootObj["前端输入功率不足判断延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 前端输入功率不足后再次输出延时 */ + if (dataType == 0x0108) { + tempValue = rootObj.value("前端输入功率不足后再次输出延时"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["input_Power_Low_Again_Output_Delay"] = tempU16; + + rootObj["前端输入功率不足后再次输出延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 第一段保护延时 */ + if (dataType == 0x0109) { + tempValue = rootObj.value("第一段保护延时"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["first_Stage_Protection_Delay"] = tempU16; + + rootObj["第一段保护延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 第一段保护的电流 */ + if (dataType == 0x010A) { + tempValue = rootObj.value("第一段保护的电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["first_Stage_Protection_Curr"] = tempF; + + rootObj["第一段保护的电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 第二段保护延时 */ + if (dataType == 0x010B) { + tempValue = rootObj.value("第二段保护延时"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["second_Stage_Protection_Delay"] = tempU16; + + rootObj["第二段保护延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 第二段保护的电流 */ + if (dataType == 0x010C) { + tempValue = rootObj.value("第二段保护的电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["second_Stage_Protection_Curr"] = tempF; + + rootObj["第二段保护的电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 第三段保护延时 */ + if (dataType == 0x010D) { + tempValue = rootObj.value("第三段保护延时"); + tempObject = tempValue.toObject(); + int tempU32 = (*(*cfgData + 2) << 24) | (*(*cfgData + 3) << 16) | (*(*cfgData + 4) << 8) | (*(*cfgData + 5)); + tempObject["third_Stage_Protection_Delay"] = tempU32; + + rootObj["第三段保护延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 6); + } + + /* 第三段保护的电流 */ + if (dataType == 0x010E) { + tempValue = rootObj.value("第三段保护的电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["third_Stage_Protection_Curr"] = tempF; + + rootObj["第三段保护的电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 前端输入功率不足检测延时 */ + if (dataType == 0x010F) { + tempValue = rootObj.value("前端输入功率不足检测延时"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["input_Power_Low_Detection_Delay"] = tempU16; + + rootObj["前端输入功率不足检测延时"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 前端输入功率不足检测电压 */ + if (dataType == 0x0110) { + tempValue = rootObj.value("前端输入功率不足检测电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["input_Power_Low_Detection_Volt"] = tempF; + + rootObj["前端输入功率不足检测电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 最大太阳能板输出电压 */ + if (dataType == 0x0111) { + tempValue = rootObj.value("最大太阳能板输出电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["max_Open_Solar_Output_Circuit_V"] = tempF; + + rootObj["最大太阳能板输出电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 最大充电电流 */ + if (dataType == 0x0112) { + tempValue = rootObj.value("最大充电电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["max_Charg_Curr"] = tempF; + + rootObj["最大充电电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 检测回路阻抗时的最小充电电流 */ + if (dataType == 0x0113) { + tempValue = rootObj.value("检测回路阻抗时的最小充电电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["min_Check_Loop_Impedance_Charg_Curr"] = tempF; + + rootObj["检测回路阻抗时的最小充电电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 全功率输出温度 */ + if (dataType == 0x0114) { + tempValue = rootObj.value("全功率输出温度"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["full_Power_Output_Temperature"] = tempF; + + rootObj["全功率输出温度"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 降功率输出温度 */ + if (dataType == 0x0115) { + tempValue = rootObj.value("降功率输出温度"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["reduce_Power_Output_Temperature"] = tempF; + + rootObj["降功率输出温度"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 停止输出温度 */ + if (dataType == 0x0116) { + tempValue = rootObj.value("停止输出温度"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["stop_PowerOutput_Temperature"] = tempF; + + rootObj["停止输出温度"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 恒压充电时的输出电压 */ + if (dataType == 0x0117) { + tempValue = rootObj.value("恒压充电时的输出电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["constant_Voltage_Charge_V"] = tempF; + + rootObj["恒压充电时的输出电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 浮充充电时的输出电压 */ + if (dataType == 0x0118) { + tempValue = rootObj.value("浮充充电时的输出电压"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["float_ChargeV"] = tempF; + + rootObj["浮充充电时的输出电压"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 充电时开路电压采集间隔 */ + if (dataType == 0x0119) { + tempValue = rootObj.value("充电时开路电压采集间隔"); + tempObject = tempValue.toObject(); + uint16_t tempU16 = (*(*cfgData + 2) << 8) | (*(*cfgData + 3)); + tempObject["collect_OpenCircuit_Voltage_Time"] = tempU16; + + rootObj["充电时开路电压采集间隔"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + /* 反向充电保护电流 */ + if (dataType == 0x011A) { + tempValue = rootObj.value("反向充电保护电流"); + tempObject = tempValue.toObject(); + float tempF = (float)((*(*cfgData + 2) << 8) | (*(*cfgData + 3))) / 10.0f; + tempObject["reverse_Charge_Protection_Curr"] = tempF; + + rootObj["反向充电保护电流"] = tempObject; + QJsonObject jsonDocObj = jsonModel->json_doc.object(); + jsonDocObj["充电控制盒配置文件"] = rootObj; + jsonModel->json_doc.setObject(jsonDocObj); + + return (*cfgData + 4); + } + + qDebug() << "analysisCfgData error" << dataType; + return NULL; } diff --git a/mainwindow.h b/mainwindow.h index b3cf48a..38e4b2a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -41,6 +41,8 @@ private: void scanSerialPort(); void parityItemInit(); + uint8_t *analysisReadCfgData(uint8_t **cfgData); + uint16_t modbusCrc(uint8_t *arr_buff, uint8_t len); private slots: