mirror of https://github.com/rusefi/RomRaider.git
Update to Logger to support signed integer ECU parameter response values
This commit is contained in:
parent
426e5b2fb7
commit
25f167e5ad
|
@ -19,8 +19,8 @@
|
|||
|
||||
<!ELEMENT conversion ( replace* ) >
|
||||
<!ATTLIST conversion expr CDATA #REQUIRED >
|
||||
<!ATTLIST conversion format ( 0 | 0.0 | 0.00 | 0.000 | 0.0000 ) #REQUIRED >
|
||||
<!ATTLIST conversion storagetype ( uint8 | uint16 | float ) #IMPLIED >
|
||||
<!ATTLIST conversion format ( 0 | 0.0 | 0.00 | 0.000 | 0.0000 | 0.00000 | 0.000000) #REQUIRED >
|
||||
<!ATTLIST conversion storagetype ( int8 | int16 | uint8 | uint16 | float ) #IMPLIED >
|
||||
<!ATTLIST conversion units CDATA #REQUIRED >
|
||||
<!ATTLIST conversion gauge_min CDATA #IMPLIED >
|
||||
<!ATTLIST conversion gauge_max CDATA #IMPLIED >
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
* Copyright (C) 2006-2013 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,31 +20,36 @@
|
|||
package com.romraider.logger.ecu.definition;
|
||||
|
||||
import static com.romraider.logger.ecu.definition.xml.ConverterMaxMinDefaults.getDefault;
|
||||
import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax;
|
||||
import static com.romraider.util.ByteUtil.asFloat;
|
||||
import static com.romraider.util.ByteUtil.asSignedInt;
|
||||
import static com.romraider.util.ByteUtil.asUnsignedInt;
|
||||
import static com.romraider.util.JEPUtil.evaluate;
|
||||
import static com.romraider.util.ParamChecker.checkNotNull;
|
||||
import static com.romraider.util.ParamChecker.checkNotNullOrEmpty;
|
||||
import static com.romraider.util.ParamChecker.isValidBit;
|
||||
import static java.lang.Float.intBitsToFloat;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax;
|
||||
|
||||
public final class EcuParameterConvertorImpl implements EcuDataConvertor {
|
||||
private final String FLOAT = "float";
|
||||
private final String INT = "int";
|
||||
private final String units;
|
||||
private final String expression;
|
||||
private final DecimalFormat format;
|
||||
private final int bit;
|
||||
private final boolean isFloat;
|
||||
private final String dataType;
|
||||
private final Map<String, String> replaceMap;
|
||||
private final GaugeMinMax gaugeMinMax;
|
||||
|
||||
public EcuParameterConvertorImpl() {
|
||||
this("Raw data", "x", "0", -1, false, new HashMap<String, String>(), getDefault());
|
||||
this("Raw data", "x", "0", -1, "uint", new HashMap<String, String>(), getDefault());
|
||||
}
|
||||
|
||||
public EcuParameterConvertorImpl(String units, String expression, String format, int bit, boolean isFloat, Map<String, String> replaceMap,
|
||||
public EcuParameterConvertorImpl(String units, String expression, String format, int bit, String dataType, Map<String, String> replaceMap,
|
||||
GaugeMinMax gaugeMinMax) {
|
||||
checkNotNullOrEmpty(units, "units");
|
||||
checkNotNullOrEmpty(expression, "expression");
|
||||
|
@ -54,7 +59,7 @@ public final class EcuParameterConvertorImpl implements EcuDataConvertor {
|
|||
this.expression = expression;
|
||||
this.format = new DecimalFormat(format);
|
||||
this.bit = bit;
|
||||
this.isFloat = isFloat;
|
||||
this.dataType = dataType;
|
||||
this.replaceMap = replaceMap;
|
||||
this.gaugeMinMax = gaugeMinMax;
|
||||
}
|
||||
|
@ -63,7 +68,16 @@ public final class EcuParameterConvertorImpl implements EcuDataConvertor {
|
|||
if (isValidBit(bit)) {
|
||||
return (bytes[0] & (1 << bit)) > 0 ? 1 : 0;
|
||||
} else {
|
||||
double value = (double) (isFloat ? intBitsToFloat(asUnsignedInt(bytes)) : asUnsignedInt(bytes));
|
||||
double value = 0;
|
||||
if (dataType != null && dataType.equalsIgnoreCase(FLOAT)) {
|
||||
value = (double) asFloat(bytes, 0 , bytes.length);
|
||||
}
|
||||
else if (dataType != null && dataType.startsWith(INT)) {
|
||||
value = (double) asSignedInt(bytes);
|
||||
}
|
||||
else {
|
||||
value = (double) asUnsignedInt(bytes);
|
||||
}
|
||||
double result = evaluate(expression, value);
|
||||
return Double.isNaN(result) || Double.isInfinite(result) ? 0.0 : result;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
* Copyright (C) 2006-2013 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -53,7 +53,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
public final class LoggerDefinitionHandler extends DefaultHandler {
|
||||
private static final String FLOAT = "float";
|
||||
private static final String TAG_LOGGER = "logger";
|
||||
private static final String TAG_PROTOCOL = "protocol";
|
||||
private static final String TAG_PARAMETER = "parameter";
|
||||
|
@ -250,7 +249,7 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
conversionExpression, conversionFormat, replaceMap, conversionGauge));
|
||||
} else {
|
||||
convertorList.add(new EcuParameterConvertorImpl(conversionUnits, conversionExpression, conversionFormat, address.getBit(),
|
||||
FLOAT.equalsIgnoreCase(conversionStorageType), replaceMap, conversionGauge));
|
||||
conversionStorageType, replaceMap, conversionGauge));
|
||||
}
|
||||
} else if (TAG_ECUPARAM.equals(qName)) {
|
||||
if (ecuInit != null && ecuAddressMap.containsKey(ecuInit.getEcuId())) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* RomRaider Open-Source Tuning, Logging and Reflashing
|
||||
* Copyright (C) 2006-2012 RomRaider.com
|
||||
* Copyright (C) 2006-2013 RomRaider.com
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -32,6 +32,20 @@ public final class ByteUtil {
|
|||
return asUnsignedInt(new byte[]{b});
|
||||
}
|
||||
|
||||
public static int asSignedInt(byte[] bytes) {
|
||||
int i = 0;
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
if (j == 0) {
|
||||
i |= bytes[j];
|
||||
}
|
||||
else {
|
||||
i <<= 8;
|
||||
i |= bytes[j] & 0xFF;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public static int asUnsignedInt(byte[] bytes) {
|
||||
int i = 0;
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
|
@ -48,7 +62,7 @@ public final class ByteUtil {
|
|||
}
|
||||
|
||||
public static float asFloat(byte[] b, int offset, int length) {
|
||||
ByteBuffer buf = ByteBuffer.wrap(b, offset, length);
|
||||
final ByteBuffer buf = ByteBuffer.wrap(b, offset, length);
|
||||
return buf.getFloat();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue