V1.0.2.0
* Added RS232/RS485 Packet Analyzer (Tools -> Packet Analyzer) * Updated BMS History register request/response length by model * Fixed decimal truncation issue in Brazil locale for DB/CSV Log and Excel Export
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using LFP_Manager.DataStructure;
|
||||
using LFP_Manager.DataStructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
@@ -564,24 +566,24 @@ namespace LFP_Manager.Utils
|
||||
p[j++].Value = aSystemData.StatusData.batteryStatus; // 7 alarm_status
|
||||
p[j++].Value = aSystemData.StatusData.warning; // 8 warning
|
||||
p[j++].Value = aSystemData.StatusData.protection; // 9 fault
|
||||
p[j++].Value = ((float)aSystemData.ValueData.voltageOfPack / 10).ToString(); // 10 module_voltage
|
||||
p[j++].Value = ((float)aSystemData.ValueData.current / 10).ToString(); // 11 module_current
|
||||
p[j++].Value = ((float)aSystemData.ValueData.rSOC / 10).ToString(); // 12 module_soc
|
||||
p[j++].Value = ((float)aSystemData.ValueData.stateOfHealth / 10).ToString(); // 13 module_soh
|
||||
p[j++].Value = ((float)aSystemData.ValueData.cycleCount / 1).ToString(); // 14 module_soh
|
||||
p[j++].Value = ((float)aSystemData.ValueData.voltageOfPack / 10).ToString(CultureInfo.InvariantCulture); // 10 module_voltage
|
||||
p[j++].Value = ((float)aSystemData.ValueData.current / 10).ToString(CultureInfo.InvariantCulture); // 11 module_current
|
||||
p[j++].Value = ((float)aSystemData.ValueData.rSOC / 10).ToString(CultureInfo.InvariantCulture); // 12 module_soc
|
||||
p[j++].Value = ((float)aSystemData.ValueData.stateOfHealth / 10).ToString(CultureInfo.InvariantCulture); // 13 module_soh
|
||||
p[j++].Value = ((float)aSystemData.ValueData.cycleCount / 1).ToString(CultureInfo.InvariantCulture); // 14 module_soh
|
||||
|
||||
for (int i = 0; i < aSystemData.cellQty; i++)
|
||||
{
|
||||
p[j++].Value = ((float)aSystemData.ValueData.CellVoltage[i] / cvUnit).ToString(); // 15 cell_voltage_01
|
||||
p[j++].Value = ((float)aSystemData.ValueData.CellVoltage[i] / cvUnit).ToString(CultureInfo.InvariantCulture); // 15 cell_voltage_01
|
||||
}
|
||||
for (int i = 0; i < aSystemData.tempQty; i++)
|
||||
{
|
||||
p[j++].Value = ((float)aSystemData.ValueData.CellTemperature[i] / 10).ToString(); // 30 temperature_01
|
||||
p[j++].Value = ((float)aSystemData.ValueData.CellTemperature[i] / 10).ToString(CultureInfo.InvariantCulture); // 30 temperature_01
|
||||
}
|
||||
p[j++].Value = ((float)aSystemData.ValueData.Ext1Temperature / 10).ToString(); // 34 temperature_ext1 - FET Temp
|
||||
p[j++].Value = ((float)aSystemData.ValueData.Ext2Temperature / 10).ToString(); // 35 temperature_ext2 - Lmt Temp
|
||||
p[j++].Value = ((float)aSystemData.ValueData.Ext1Temperature / 10).ToString(CultureInfo.InvariantCulture); // 34 temperature_ext1 - FET Temp
|
||||
p[j++].Value = ((float)aSystemData.ValueData.Ext2Temperature / 10).ToString(CultureInfo.InvariantCulture); // 35 temperature_ext2 - Lmt Temp
|
||||
|
||||
p[j++].Value = aSystemData.CalibrationData.ChaMode.Mode.ToString(); // 36 chg_option
|
||||
p[j++].Value = aSystemData.CalibrationData.ChaMode.Mode.ToString(CultureInfo.InvariantCulture); // 36 chg_option
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
@@ -1011,6 +1013,57 @@ namespace LFP_Manager.Utils
|
||||
|
||||
#region SELECT QUARY
|
||||
|
||||
public static void RepairCommaDecimalsIfNeeded(SQLiteConnection connection)
|
||||
{
|
||||
try
|
||||
{
|
||||
bool hasCommaText = false;
|
||||
using (SQLiteCommand checkCmd = connection.CreateCommand())
|
||||
{
|
||||
checkCmd.CommandText = "SELECT 1 FROM TModuleValue WHERE typeof(module_voltage) = 'text' OR typeof(cell_voltage_01) = 'text' LIMIT 1";
|
||||
object res = checkCmd.ExecuteScalar();
|
||||
hasCommaText = (res != null && res != DBNull.Value);
|
||||
}
|
||||
|
||||
if (!hasCommaText) return;
|
||||
|
||||
List<string> numCols = new List<string>();
|
||||
using (SQLiteCommand pragmaCmd = connection.CreateCommand())
|
||||
{
|
||||
pragmaCmd.CommandText = "PRAGMA table_info(TModuleValue);";
|
||||
using (SQLiteDataReader reader = pragmaCmd.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
string colName = Convert.ToString(reader["name"]);
|
||||
string colType = Convert.ToString(reader["type"]).ToUpperInvariant();
|
||||
if (colType.Contains("NUMERIC") || colType.Contains("REAL") || colType.Contains("DOUBLE") || colType.Contains("FLOAT") || colType.Contains("DECIMAL"))
|
||||
{
|
||||
numCols.Add(colName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numCols.Count == 0) return;
|
||||
|
||||
List<string> setClauses = new List<string>(numCols.Count);
|
||||
foreach (string col in numCols)
|
||||
{
|
||||
setClauses.Add(string.Format("{0} = CASE WHEN typeof({0}) = 'text' THEN CAST(REPLACE({0}, ',', '.') AS NUMERIC) ELSE {0} END", col));
|
||||
}
|
||||
|
||||
using (SQLiteCommand updateCmd = connection.CreateCommand())
|
||||
{
|
||||
updateCmd.CommandText = "UPDATE TModuleValue SET " + string.Join(", ", setClauses.ToArray());
|
||||
updateCmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static int DbQuaryExcuteToDataTable(string dbFileName, string Quary, ref DataTable rDT)
|
||||
{
|
||||
int result = 0;
|
||||
@@ -1023,6 +1076,7 @@ namespace LFP_Manager.Utils
|
||||
{
|
||||
connection.Open();
|
||||
BeginTran(connection);
|
||||
RepairCommaDecimalsIfNeeded(connection);
|
||||
|
||||
// Insert data
|
||||
using (SQLiteCommand command = connection.CreateCommand())
|
||||
@@ -1255,6 +1309,7 @@ namespace LFP_Manager.Utils
|
||||
{
|
||||
connection.Open();
|
||||
BeginTran(connection);
|
||||
RepairCommaDecimalsIfNeeded(connection);
|
||||
|
||||
// Insert data
|
||||
using (SQLiteCommand command = connection.CreateCommand())
|
||||
|
||||
Reference in New Issue
Block a user