diff --git a/chargControlBox_cfgFile.pro.user b/chargControlBox_cfgFile.pro.user index 1c08574..df30194 100644 --- a/chargControlBox_cfgFile.pro.user +++ b/chargControlBox_cfgFile.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/mainwindow.cpp b/mainwindow.cpp index 25a194d..a4fea6d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1234,19 +1234,25 @@ void MainWindow::writeCfgFile() tempValue = rootObj.value("恒压充电阈值电压"); tempValue = tempObject.value("constant_Voltage_V"); + float tempFloat; if (tempValue.isString()) { tempString = tempValue.toString(); + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + } + else if (tempValue.isDouble()) { + tempFloat = tempValue.toDouble(); } else { - qDebug() << "constant_Voltage_V error" << tempValue.type() ; + qDebug() << "constant_Voltage_V error" << tempValue.type(); return; } - float tempFloat = tempString.toFloat(&ok); - if (!ok) { - qDebug() << "转换失败!"; - return; - } - tempU16 = tempFloat * 10; + + qDebug() << "constant_Voltage_V:" << tempFloat; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -1287,17 +1293,25 @@ void MainWindow::writeCfgFile() tempValue = tempObject.value("float_I"); if (tempValue.isString()) { tempString = tempValue.toString(); + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + } + else if (tempValue.isDouble()) { + tempFloat = tempValue.toDouble(); } else { qDebug() << "float_I error" << tempValue.type() ; return; } - tempFloat = tempString.toFloat(&ok); - if (!ok) { - qDebug() << "转换失败!"; - return; - } - tempU16 = tempFloat * 10; +// tempFloat = tempString.toFloat(&ok); +// if (!ok) { +// qDebug() << "转换失败!"; +// return; +// } + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -1336,19 +1350,28 @@ void MainWindow::writeCfgFile() tempValue = rootObj.value("启动充电太阳能板开路电压"); tempValue = tempObject.value("start_Solar_Open_Circuit_V"); + if (tempValue.isString()) { tempString = tempValue.toString(); + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + } + else if (tempValue.isDouble()) { + tempFloat = tempValue.toDouble(); } else { qDebug() << "start_Solar_Open_Circuit_V error" << tempValue.type() ; return; } - tempFloat = tempString.toFloat(&ok); - if (!ok) { - qDebug() << "转换失败!"; - return; - } - tempU16 = tempFloat * 10; +// tempFloat = tempString.toFloat(&ok); +// if (!ok) { +// qDebug() << "转换失败!"; +// return; +// } + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -1386,20 +1409,28 @@ void MainWindow::writeCfgFile() dataLen += 2; tempValue = rootObj.value("停止充电太阳能板输出电压"); - tempValue = tempObject.value("stop_Solar_Output_Circuit_V"); + tempValue = tempObject.value("stop_Solar_Output_Circuit_V"); if (tempValue.isString()) { tempString = tempValue.toString(); + tempFloat = tempString.toFloat(&ok); + if (!ok) { + qDebug() << "转换失败!"; + return; + } + } + else if (tempValue.isDouble()) { + tempFloat = tempValue.toDouble(); } else { qDebug() << "stop_Solar_Output_Circuit_V error" << tempValue.type() ; return; } - tempFloat = tempString.toFloat(&ok); - if (!ok) { - qDebug() << "转换失败!"; - return; - } - tempU16 = tempFloat * 10; +// tempFloat = tempString.toFloat(&ok); +// if (!ok) { +// qDebug() << "转换失败!"; +// return; +// } + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -1700,7 +1731,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -1801,7 +1832,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -1906,7 +1937,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2007,7 +2038,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2058,7 +2089,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2089,6 +2120,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } + qDebug() << "最大充电电流 类型" << tempU16; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2109,7 +2141,9 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + qDebug() << "最大充电电流" << tempFloat; + qDebug() << "最大充电电流" << tempU16; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2160,7 +2194,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2211,7 +2245,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2262,7 +2296,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2313,7 +2347,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2361,11 +2395,13 @@ void MainWindow::writeCfgFile() return; } tempFloat = tempString.toFloat(&ok); + qDebug() << "constant_Voltage_Charge_V" << tempFloat; if (!ok) { qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); +// qDebug() << "constant_Voltage_Charge_V * 10" << tempU16; *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16; @@ -2416,7 +2452,7 @@ void MainWindow::writeCfgFile() qDebug() << "转换失败!"; return; } - tempU16 = tempFloat * 10; + tempU16 = (uint16_t)(tempFloat * 10 + 0.5f); *writeCfgPoint = (uint8_t)(tempU16 >> 8); writeCfgPoint += 1; *writeCfgPoint = (uint8_t)tempU16;