Fixed dyno locale problem

This commit is contained in:
Robin 2021-06-21 17:42:43 +02:00
parent a99f3c8efd
commit a1adb99be9
4 changed files with 45 additions and 69 deletions

View File

@ -19,22 +19,12 @@
package com.romraider.logger.car.util; package com.romraider.logger.car.util;
public enum Constants { public class Constants {
IMPERIAL ("imperial"), static String IMPERIAL = "imperial";
IMPERIAL_UNIT ("mph"), static String METRIC = "metric";
METRIC ("metric"), static String METRIC_UNIT = "km/h";
METRIC_UNIT ("km/h"), static String IMPERIAL_UNIT = "mph";
KPH_2_MPH ("1.609344"), static double KPH_2_MPH = 1.609344;
TQ_CONSTANT_I ("5252.113122"), static double TQ_CONSTANT_I = 5252.113122;
TQ_CONSTANT_M ("9549.296748"); static double TQ_CONSTANT_M = 9549.296748;
private final String value;
Constants (String value) {
this.value = value;
}
public String value(){
return value;
}
} }

View File

@ -24,20 +24,18 @@ import static com.romraider.logger.car.util.Constants.KPH_2_MPH;
import static com.romraider.logger.car.util.Constants.METRIC_UNIT; import static com.romraider.logger.car.util.Constants.METRIC_UNIT;
public class SpeedCalculator { public class SpeedCalculator {
private static final double K2M = Double.parseDouble(KPH_2_MPH.value());
public static double calculateMph(double rpm, double ratio) { public static double calculateMph(double rpm, double ratio) {
return (rpm / ratio); return (rpm / ratio);
} }
public static double calculateKph(double rpm, double ratio) { public static double calculateKph(double rpm, double ratio) {
return calculateMph(rpm, ratio) * K2M; return calculateMph(rpm, ratio) * KPH_2_MPH;
} }
public static double calculateRpm(double vs, double ratio, String units) { public static double calculateRpm(double vs, double ratio, String units) {
double rpm = 0; double rpm = 0;
if (units.equalsIgnoreCase(IMPERIAL_UNIT.value())) rpm = (vs * ratio); if (units.equalsIgnoreCase(IMPERIAL_UNIT)) rpm = (vs * ratio);
if (units.equalsIgnoreCase(METRIC_UNIT.value())) rpm = (vs * ratio / K2M); if (units.equalsIgnoreCase(METRIC_UNIT)) rpm = (vs * ratio / KPH_2_MPH);
return rpm; return rpm;
} }

View File

@ -28,11 +28,11 @@ public class TorqueCalculator {
public static double calculateTorque(double rpm, double hp, String units) { public static double calculateTorque(double rpm, double hp, String units) {
double tq = 0; double tq = 0;
if (units.equalsIgnoreCase(IMPERIAL.value())) { if (units.equalsIgnoreCase(IMPERIAL)) {
tq = hp / rpm * Double.parseDouble(TQ_CONSTANT_I.value()); tq = hp / rpm * TQ_CONSTANT_I;
} }
if (units.equalsIgnoreCase(METRIC.value())) { if (units.equalsIgnoreCase(METRIC)) {
tq = hp / rpm * Double.parseDouble(TQ_CONSTANT_M.value()); tq = hp / rpm * TQ_CONSTANT_M;
} }
return tq; return tq;
} }

View File

@ -1042,31 +1042,35 @@ public final class DynoControlPanel extends JPanel {
"; RPM Column: " + rpmCol + "; TA Column: " + taCol + "; VS Column: " + vsCol + "; RPM Column: " + rpmCol + "; TA Column: " + taCol + "; VS Column: " + vsCol +
"; VS units: " + vsLogUnits); "; VS units: " + vsLogUnits);
while ((line = inputStream.readLine()) != null) { while ((line = inputStream.readLine()) != null) {
//Convert everything to . notation
line = line.replace(',', '.');
String[] values = line.split(delimiter); String[] values = line.split(delimiter);
if (NumberUtil.doubleValue(values[taCol]) > tpsMin) {
if (Double.parseDouble(values[taCol]) > tpsMin) {
double logTime = 0; double logTime = 0;
if (atrTime) { if (atrTime) {
String[] timeStamp = values[timeCol].split(COLON); String[] timeStamp = values[timeCol].split(COLON);
if (timeStamp.length == 3) { if (timeStamp.length == 3) {
logTime = (NumberUtil.doubleValue(timeStamp[0]) * 3600) + logTime = (Double.parseDouble(timeStamp[0]) * 3600) +
(NumberUtil.doubleValue(timeStamp[1]) * 60) + (Double.parseDouble(timeStamp[1]) * 60) +
NumberUtil.doubleValue(timeStamp[2]) * timeMult; Double.parseDouble(timeStamp[2]) * timeMult;
} else { } else {
logTime = (NumberUtil.doubleValue(timeStamp[0]) * 60) + logTime = (Double.parseDouble(timeStamp[0]) * 60) +
NumberUtil.doubleValue(timeStamp[1]) * timeMult; Double.parseDouble(timeStamp[1]) * timeMult;
} }
} else { } else {
logTime = NumberUtil.doubleValue(values[timeCol]) * timeMult; logTime = Double.parseDouble(values[timeCol]) * timeMult;
} }
if (startTime == -999999999) startTime = logTime; if (startTime == -999999999) startTime = logTime;
logTime = logTime - startTime; logTime = logTime - startTime;
double logRpm = 0; double logRpm = 0;
if (isManual()) { if (isManual()) {
logRpm = NumberUtil.doubleValue(values[rpmCol]); logRpm = Double.parseDouble(values[rpmCol]);
minRpm = Math.min(minRpm, logRpm); minRpm = Math.min(minRpm, logRpm);
maxRpm = Math.max(maxRpm, logRpm); maxRpm = Math.max(maxRpm, logRpm);
} else { } else {
logRpm = NumberUtil.doubleValue(values[vsCol]); logRpm = Double.parseDouble(values[vsCol]);
minRpm = Math.min(minRpm, calculateRpm(logRpm, rpm2mph, vsLogUnits)); minRpm = Math.min(minRpm, calculateRpm(logRpm, rpm2mph, vsLogUnits));
maxRpm = Math.max(maxRpm, calculateRpm(logRpm, rpm2mph, vsLogUnits)); maxRpm = Math.max(maxRpm, calculateRpm(logRpm, rpm2mph, vsLogUnits));
} }
@ -1082,9 +1086,6 @@ public final class DynoControlPanel extends JPanel {
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
catch (ParseException e) {
e.printStackTrace();
}
finally { finally {
if (inputStream != null) { if (inputStream != null) {
try { try {
@ -1449,12 +1450,8 @@ public final class DynoControlPanel extends JPanel {
} }
private double parseDouble(JTextField field) { private double parseDouble(JTextField field) {
try { String s = field.getText().trim().replace(',', '.');
return NumberUtil.doubleValue(field.getText().trim()); return Double.parseDouble(s);
} catch (ParseException e) {
LOGGER.error(rb.getString("ERROR"), e);
}
return Double.parseDouble("NaN");
} }
public void setEcuParams(List<EcuParameter> params) { public void setEcuParams(List<EcuParameter> params) {
@ -1555,33 +1552,24 @@ public final class DynoControlPanel extends JPanel {
private void loadCars() { private void loadCars() {
try { try {
File carDef = null; File carDef = null;
final String SEPARATOR = System.getProperty("file.separator");
final String loggerFilePath = getSettings().getLoggerDefinitionFilePath(); //Look through some folders to find the car definition file
//Do NOT delete the "", this also searches through the local folder!
final String searchPaths[] = {getSettings().getLoggerDefinitionFilePath(), getSettings().getLoggerProfileFilePath(), ""};
if(loggerFilePath != null) { for (String s : searchPaths) {
final int index = loggerFilePath.lastIndexOf(SEPARATOR); File f = new File(s);
if (index > 0) { File path_test = new File(f.getParent(), CARS_FILE);
final String path = loggerFilePath.substring(0, index + 1);
carDef = new File(path + CARS_FILE); if(path_test.exists()) {
} LOGGER.info("Loaded dyno definition file from " + path_test.getAbsolutePath());
carDef = path_test;
break;
}
} }
if (!carDef.exists()) { if(carDef == null) throw new FileNotFoundException(MISSING_CAR_DEF);
final String profileFilePath = getSettings().getLoggerProfileFilePath();
if (profileFilePath != null) {
final int index = profileFilePath.lastIndexOf(SEPARATOR);
if (index > 0) {
final String path = profileFilePath.substring(0, index + 1);
carDef = new File(path + CARS_FILE);
}
}
}
if (!carDef.exists()) {
carDef = new File(CARS_FILE);
}
if (!carDef.exists()) {
throw new FileNotFoundException(MISSING_CAR_DEF);
}
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document carsDef = docBuilder.parse(carDef); Document carsDef = docBuilder.parse(carDef);