修改浮点数精度引起的错误
This commit is contained in:
parent
240509beb4
commit
5ab8399916
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE QtCreatorProject>
|
<!DOCTYPE QtCreatorProject>
|
||||||
<!-- Written by QtCreator 4.12.2, 2025-01-22T14:45:17. -->
|
<!-- Written by QtCreator 4.12.2, 2025-01-23T17:09:40. -->
|
||||||
<qtcreator>
|
<qtcreator>
|
||||||
<data>
|
<data>
|
||||||
<variable>EnvironmentId</variable>
|
<variable>EnvironmentId</variable>
|
||||||
|
|
108
mainwindow.cpp
108
mainwindow.cpp
|
@ -1234,19 +1234,25 @@ void MainWindow::writeCfgFile()
|
||||||
|
|
||||||
tempValue = rootObj.value("恒压充电阈值电压");
|
tempValue = rootObj.value("恒压充电阈值电压");
|
||||||
tempValue = tempObject.value("constant_Voltage_V");
|
tempValue = tempObject.value("constant_Voltage_V");
|
||||||
|
float tempFloat;
|
||||||
if (tempValue.isString()) {
|
if (tempValue.isString()) {
|
||||||
tempString = tempValue.toString();
|
tempString = tempValue.toString();
|
||||||
|
tempFloat = tempString.toFloat(&ok);
|
||||||
|
if (!ok) {
|
||||||
|
qDebug() << "转换失败!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tempValue.isDouble()) {
|
||||||
|
tempFloat = tempValue.toDouble();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
qDebug() << "constant_Voltage_V error" << tempValue.type();
|
qDebug() << "constant_Voltage_V error" << tempValue.type();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float tempFloat = tempString.toFloat(&ok);
|
|
||||||
if (!ok) {
|
qDebug() << "constant_Voltage_V:" << tempFloat;
|
||||||
qDebug() << "转换失败!";
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
return;
|
|
||||||
}
|
|
||||||
tempU16 = tempFloat * 10;
|
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -1287,17 +1293,25 @@ void MainWindow::writeCfgFile()
|
||||||
tempValue = tempObject.value("float_I");
|
tempValue = tempObject.value("float_I");
|
||||||
if (tempValue.isString()) {
|
if (tempValue.isString()) {
|
||||||
tempString = tempValue.toString();
|
tempString = tempValue.toString();
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug() << "float_I error" << tempValue.type() ;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tempFloat = tempString.toFloat(&ok);
|
tempFloat = tempString.toFloat(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
}
|
||||||
|
else if (tempValue.isDouble()) {
|
||||||
|
tempFloat = tempValue.toDouble();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
qDebug() << "float_I error" << tempValue.type() ;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// tempFloat = tempString.toFloat(&ok);
|
||||||
|
// if (!ok) {
|
||||||
|
// qDebug() << "转换失败!";
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -1336,19 +1350,28 @@ void MainWindow::writeCfgFile()
|
||||||
|
|
||||||
tempValue = rootObj.value("启动充电太阳能板开路电压");
|
tempValue = rootObj.value("启动充电太阳能板开路电压");
|
||||||
tempValue = tempObject.value("start_Solar_Open_Circuit_V");
|
tempValue = tempObject.value("start_Solar_Open_Circuit_V");
|
||||||
|
|
||||||
if (tempValue.isString()) {
|
if (tempValue.isString()) {
|
||||||
tempString = tempValue.toString();
|
tempString = tempValue.toString();
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug() << "start_Solar_Open_Circuit_V error" << tempValue.type() ;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tempFloat = tempString.toFloat(&ok);
|
tempFloat = tempString.toFloat(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
}
|
||||||
|
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 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -1389,17 +1412,25 @@ void MainWindow::writeCfgFile()
|
||||||
tempValue = tempObject.value("stop_Solar_Output_Circuit_V");
|
tempValue = tempObject.value("stop_Solar_Output_Circuit_V");
|
||||||
if (tempValue.isString()) {
|
if (tempValue.isString()) {
|
||||||
tempString = tempValue.toString();
|
tempString = tempValue.toString();
|
||||||
}
|
|
||||||
else {
|
|
||||||
qDebug() << "stop_Solar_Output_Circuit_V error" << tempValue.type() ;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tempFloat = tempString.toFloat(&ok);
|
tempFloat = tempString.toFloat(&ok);
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
}
|
||||||
|
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 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -1700,7 +1731,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -1801,7 +1832,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -1906,7 +1937,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2007,7 +2038,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2058,7 +2089,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2089,6 +2120,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
qDebug() << "最大充电电流 类型" << tempU16;
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2109,7 +2141,9 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
qDebug() << "最大充电电流" << tempFloat;
|
||||||
|
qDebug() << "最大充电电流" << tempU16;
|
||||||
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2160,7 +2194,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2211,7 +2245,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2262,7 +2296,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2313,7 +2347,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2361,11 +2395,13 @@ void MainWindow::writeCfgFile()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempFloat = tempString.toFloat(&ok);
|
tempFloat = tempString.toFloat(&ok);
|
||||||
|
qDebug() << "constant_Voltage_Charge_V" << tempFloat;
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
|
// qDebug() << "constant_Voltage_Charge_V * 10" << tempU16;
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
@ -2416,7 +2452,7 @@ void MainWindow::writeCfgFile()
|
||||||
qDebug() << "转换失败!";
|
qDebug() << "转换失败!";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tempU16 = tempFloat * 10;
|
tempU16 = (uint16_t)(tempFloat * 10 + 0.5f);
|
||||||
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
*writeCfgPoint = (uint8_t)(tempU16 >> 8);
|
||||||
writeCfgPoint += 1;
|
writeCfgPoint += 1;
|
||||||
*writeCfgPoint = (uint8_t)tempU16;
|
*writeCfgPoint = (uint8_t)tempU16;
|
||||||
|
|
Loading…
Reference in New Issue