Browse Source

Fix #173 - False values O2-Lambda-Sensor

- Add mnemonic table to EcuDataItems
- Add optional dynamic factor to LinearConversion
- Reference PID data for dynamic factor in conversion
master
fr3ts0n 4 weeks ago
parent
commit
382fdab4e3
  1. 25
      library/src/main/java/com/fr3ts0n/ecu/EcuConversions.java
  2. 28
      library/src/main/java/com/fr3ts0n/ecu/EcuDataItems.java
  3. 50
      library/src/main/java/com/fr3ts0n/ecu/LinearConversion.java
  4. 8
      library/src/main/java/com/fr3ts0n/ecu/prot/obd/res/conversions.csv
  5. 22
      library/src/main/java/com/fr3ts0n/ecu/prot/obd/res/pids.csv

25
library/src/main/java/com/fr3ts0n/ecu/EcuConversions.java

@ -116,12 +116,25 @@ public class EcuConversions extends HashMap<String, Conversion[]>
params = currLine.split("\t");
if (params[FLD_TYPE].equals(CNV_TYPE_LINEAR))
{
// create linear conversion
newCnv = new LinearConversion(Integer.parseInt(params[FLD_FACTOR]),
Integer.parseInt(params[FLD_DIVIDER]),
Integer.parseInt(params[FLD_OFFSET]),
Integer.parseInt(params[FLD_PHOFFSET]),
params[FLD_UNITS]);
if(params.length > FLD_PARAMETERS)
{
// create linear conversion (w/ dynamic parameters)
newCnv = new LinearConversion(Integer.parseInt(params[FLD_FACTOR]),
Integer.parseInt(params[FLD_DIVIDER]),
Integer.parseInt(params[FLD_OFFSET]),
Integer.parseInt(params[FLD_PHOFFSET]),
params[FLD_UNITS],
params[FLD_PARAMETERS]);
}
else
{
// create linear conversion (w/o dynamic parameter)
newCnv = new LinearConversion(Integer.parseInt(params[FLD_FACTOR]),
Integer.parseInt(params[FLD_DIVIDER]),
Integer.parseInt(params[FLD_OFFSET]),
Integer.parseInt(params[FLD_PHOFFSET]),
params[FLD_UNITS]);
}
}
else if (params[FLD_TYPE].equals(CNV_TYPE_HASH))
{

28
library/src/main/java/com/fr3ts0n/ecu/EcuDataItems.java

@ -45,9 +45,14 @@ import java.util.logging.Logger;
*/
public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDataItem>>>
{
/** SerialVerion UID */
/**
* SerialVersion UID
*/
private static final long serialVersionUID = 5525561909111851836L;
/** CSV field positions */
/**
* CSV field positions
*/
enum FLD
{
SVC,
@ -71,6 +76,8 @@ public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDa
public static EcuConversions cnv;
// the data logger
private static final Logger log = Logger.getLogger("data.items");
// map of MNEMONIC data item
protected static final HashMap<String, EcuDataItem> byMnemonic = new HashMap<>();
/**
* Create data items from default CSV pidResource files
@ -78,14 +85,15 @@ public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDa
*/
public EcuDataItems()
{
this( "prot/obd/res/pids.csv",
"prot/obd/res/conversions.csv",
"com.fr3ts0n.ecu.prot.obd.res.messages");
this("prot/obd/res/pids.csv",
"prot/obd/res/conversions.csv",
"com.fr3ts0n.ecu.prot.obd.res.messages");
}
/**
* Create data items from CSV pidResource file
* @param pidResource resource file for PIDs (csv)
*
* @param pidResource resource file for PIDs (csv)
* @param conversionResource resource file for conversions (csv)
*/
public EcuDataItems(String pidResource, String conversionResource, String resourceBundleName)
@ -169,6 +177,9 @@ public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDa
label,
params[FLD.MNEMONIC.ordinal()]);
// Add item to mnemonic map
byMnemonic.put(params[FLD.MNEMONIC.ordinal()], newItm);
// enter data item for all specified services
String[] services = params[FLD.SVC.ordinal()].split(","); //$NON-NLS-1$
for (String service : services)
@ -214,7 +225,7 @@ public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDa
HashMap<Integer, Vector<EcuDataItem>> currSvc = get(service);
if (currSvc != null)
{
for(Vector<EcuDataItem> currVec : currSvc.values())
for (Vector<EcuDataItem> currVec : currSvc.values())
{
result.addAll(currVec);
}
@ -224,6 +235,7 @@ public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDa
/**
* append new data item to specified service
*
* @param service service to add item to
* @param newItem EcuDataItem to be added
*/
@ -253,7 +265,7 @@ public class EcuDataItems extends HashMap<Integer, HashMap<Integer, Vector<EcuDa
// update map of services
put(service, currSvc);
// debug message of new enty
log.finer("+" + service + "/" + String.format("0x%02X",newItem.pid) + " - " + currVec); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
log.finer("+" + service + "/" + String.format("0x%02X", newItem.pid) + " - " + currVec); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
/**

50
library/src/main/java/com/fr3ts0n/ecu/LinearConversion.java

@ -37,6 +37,8 @@ public class LinearConversion extends NumericConversion
private int offset = 0;
private int offsetPhys = 0;
private PvLimits limits = null;
// mnemonic of dynamic factor
private String factMnemonic = null;
/**
* Creates a new instance of Conversion
@ -64,6 +66,26 @@ public class LinearConversion extends NumericConversion
this.units = units;
}
/**
* Creates a new instance of Conversion with usage of a optional dynamic conversion factor
*
* @param factor conversion factor (integer part)
* @param divider conversion divider (integer part)
* @param offset linear offset to be added to raw memory value before conversion
* @param offsetPhys physical offset to be added after converting raw value
* @param units physical units for this conversion
* @param factMnemonic mnemonic of dynamic conversion factor value
*/
public LinearConversion(int factor, int divider, int offset, int offsetPhys,
String units, String factMnemonic)
{
this(factor, divider, offset, offsetPhys, units);
if (factMnemonic != null && !factMnemonic.isEmpty())
{
this.factMnemonic = factMnemonic;
}
}
/**
* Creates a new instance of Conversion
*
@ -80,6 +102,33 @@ public class LinearConversion extends NumericConversion
this.limits = limits;
}
/**
* Dynamic update of conversion factor from other measurement value
*
* The dynamic conversion factor overrides the initial, static factor if:
* - Factor is reported by protocol
* - Value > 0
*/
private void updateCnvFromDynamicFactor()
{
if (factMnemonic != null)
{
// Get data item of dynamic conversion factor
EcuDataItem newFactItm = EcuDataItems.byMnemonic.get(factMnemonic);
if (newFactItm != null)
{
// Get value of dynamic conversion factor
Number factVal = (Number)newFactItm.pv.get(EcuDataPv.FID_VALUE);
// If there is a valid value, update factor with dynamic factor
if (factVal != null && factVal.intValue() > 0)
{
// update conversion factor from dynamic value
factor = factVal.intValue();
}
}
}
}
/**
* convert measurement item from storage format to physical value
*
@ -87,6 +136,7 @@ public class LinearConversion extends NumericConversion
*/
public Number memToPhys(long value)
{
updateCnvFromDynamicFactor();
float result = ((float) (value + offset) * factor / divider + offsetPhys);
if (limits != null)
{

8
library/src/main/java/com/fr3ts0n/ecu/prot/obd/res/conversions.csv

@ -6,7 +6,7 @@ AIRFLOW_WIDE LINEAR 0 METRIC 1 32 0 0 g/s Air Flow
ANGLE LINEAR 0 METRIC 1 2 -128 0 ° Angle (Timing adv)
ANGLE_WIDERANGE LINEAR 0 METRIC 1 128 -26880 0 ° Angle wide range (Injection)
ASCII ASCII 0 METRIC 1 1 0 0 ASCII
CURRENT LINEAR 0 METRIC 1 1 0 0 mA Current
CURRENT LINEAR 0 METRIC 1 1 0 0 mA Current
DISTANCE LINEAR 0 IMPERIAL 1000 1609 0 0 miles Distance
DISTANCE LINEAR 0 METRIC 1 1 0 0 km Distance
EGT_SENSORS BITMAP 0 METRIC 1 1 0 0 Exhaust Gas Temperature sensors 0=S1;1=S2;2=S3;3=S4
@ -19,13 +19,13 @@ HOURS LINEAR 0 METRIC 1 3600 0 0 h Time (hours)
HOURS_FULL LINEAR 0 METRIC 1 1 0 0 h Time (hours)
IGN_MON_STATUS BITMAP 0 METRIC 1 1 0 0 Ignition monitor status 0=Compression ignition monitor available
INTEGER INTEGER 0 METRIC 1 1 0 0 INTEGER
LAMBDA LINEAR 0 METRIC 1 32768 0 0 - Lambda (0-2)
LAMBDA LINEAR 0 METRIC 2 65535 0 0 Lambda (0-2) equiv_ratio_max
LAMBDA_O2 LINEAR 0 METRIC 1 8192 0 0 O2 Lambda (PID 8C)
O2_CURRENT LINEAR 0 METRIC 1 256 0 -128 mA O2 current
O2_CURRENT LINEAR 0 METRIC 128 32768 -32768 0 mA O2 current o2_sensor_current_max
O2_PERCENT LINEAR 0 METRIC 100 128 -128 0 % 8-Bit percentage (O2)
O2_PRESENT_MAP BITMAP 0 METRIC 1 1 0 0 O2-Sensors present 0=B1S1;1=B1S2;2=B2S1;3=B2S2;4=B3S1;5=B3S2;6=B4S1;7=B4S2
O2_PRESENT13 BITMAP 0 METRIC 1 1 0 0 O2-Sensors present 0=B1S1;1=B1S2;2=B1S3;3=B1S4;4=B2S1;5=B2S2;6=B2S3;7=B2S4
O2_VOLT_WIDE LINEAR 0 METRIC 8000 65536 0 0 mV 16-Bit O2 Voltage (0-8V)
O2_VOLT_WIDE LINEAR 0 METRIC 8 65535 0 0 V 16-Bit O2 Voltage (0-8V) o2_sensor_voltage_max
O2_VOLTAGE LINEAR 0 METRIC 5 1 0 0 mV 8-Bit O2 Voltage
OBD_CODELIST PCODELIST 0 METRIC 1 1 0 0 Code list conversion com.fr3ts0n.ecu.prot.obd.res.codes
OBD_REQUIREMENTS HASH 0 METRIC 1 1 0 0 OBD requirements 14=Heavy Duty Vehicles (EURO IV) B1;15=Heavy Duty Vehicles (EURO V) B2;16=Heavy Duty Vehicles (EURO EEV) C

22
library/src/main/java/com/fr3ts0n/ecu/prot/obd/res/pids.csv

@ -56,21 +56,21 @@ svc pid ofs len bit_offset bit_length bit_mask formula format min max mnemonic (
0x01,0x02 0x22 0 2 0 16 0xFFFF PRESS_REL %.3f fuel_pressure_rel Fuel Rail Pressure (rel. to manifold vacuum) fuel rail pressure relative to manifold vacuum
0x01,0x02 0x23 0 2 0 16 0xFFFF PRESS_WIDERANGE %.1f fuel_pressure Fuel Pressure (gauge) fuel rail pressure (gauge wide range
0x01,0x02 0x24 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b1s1 O2 Sensor B1S1 lambda Bank 1 (WR) o2_sensor_wrv_formula -o2 sensors (wide range voltage
0x01,0x02 0x24 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b1s1 O2 Sensor B1S1 Bank 1 (WR) o2_sensor_wrv_formula -o2 sensors (wide range voltage
0x01,0x02 0x24 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b1s1 O2 Sensor B1S1 Bank 1 (WR) o2_sensor_wrv_formula -o2 sensors (wide range voltage
0x01,0x02 0x25 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b1s2 O2 Sensor B1S2 lambda Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x25 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b1s2 O2 Sensor B1S2 Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x25 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b1s2 O2 Sensor B1S2 Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x26 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b1s3 O2 Sensor B1S3 lambda Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x26 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b1s3 O2 Sensor B1S3 Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x26 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b1s3 O2 Sensor B1S3 Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x27 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b1s4 O2 Sensor B1S4 lambda Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x27 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b1s4 O2 Sensor B1S4 Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x27 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b1s4 O2 Sensor B1S4 Bank 1 (WR) o2_sensor_wrv_formula
0x01,0x02 0x28 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b2s1 O2 Sensor B2S1 lambda Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x28 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b2s1 O2 Sensor B2S1 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x28 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b2s1 O2 Sensor B2S1 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x29 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b2s2 O2 Sensor B2S2 lambda Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x29 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b2s2 O2 Sensor B2S2 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x29 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b2s2 O2 Sensor B2S2 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2A 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b2s3 O2 Sensor B2S3 lambda Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2A 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b2s3 O2 Sensor B2S3 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2A 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b2s3 O2 Sensor B2S3 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2B 0 2 0 16 0xFFFF LAMBDA %.3f 0.5 1.5 o2_sensor_lambda_b2s4 O2 Sensor B2S4 lambda Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2B 2 2 0 16 0xFFFF O2_VOLT_WIDE %.0f o2_sensor_voltage_b2s4 O2 Sensor B2S4 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2B 2 2 0 16 0xFFFF O2_VOLT_WIDE %.3f o2_sensor_voltage_b2s4 O2 Sensor B2S4 Bank 2 (WR) o2_sensor_wrv_formula
0x01,0x02 0x2C 0 1 0 8 0xFF PERCENT %.1f egr_ratio_commanded Commanded EGR
0x01,0x02 0x2D 0 1 0 8 0xFF PERCENT_REL %.2f egr_error EGR Error
0x01,0x02 0x2E 0 1 0 8 0xFF PERCENT %.1f evaporative_purge_ratio Commanded Evaporative Purge
@ -125,9 +125,9 @@ svc pid ofs len bit_offset bit_length bit_mask formula format min max mnemonic (
0x01,0x02 0x4D 0 2 0 16 0xFFFF HOURS %.2f time_since_mil_on Engine running while MIL on minutes run by the engine while MIL activated
0x01,0x02 0x4E 0 2 0 16 0xFFFF HOURS %.2f time_since_ecu_reset Time since DTCs cleared
0x01,0x02 0x4F 0 1 0 8 0xFF ONETOONE %.0f equiv_ratio_max Maximum equivalence ratio
0x01,0x02 0x4F 1 1 0 8 0xFF VOLTAGE_MV %.0f o2_sensor_voltage_max Maximum oxygen sensor voltage
0x01,0x02 0x4F 2 1 0 8 0xFF CURRENT %.0f o2_sensor_current_max Maximum oxygen sensor current
0x01,0x02 0x4F 3 1 0 8 0xFF PRESS_WIDERANGE %.0f fuel_pressure_max Maximum intake manifold absolute pressure
0x01,0x02 0x4F 1 1 0 8 0xFF ONETOONE %.0f o2_sensor_voltage_max Maximum oxygen sensor voltage
0x01,0x02 0x4F 2 1 0 8 0xFF ONETOONE %.0f o2_sensor_current_max Maximum oxygen sensor current
0x01,0x02 0x4F 3 1 0 8 0xFF ONETOONE %.0f fuel_pressure_max Maximum intake manifold absolute pressure
0x01,0x02 0x50 0 1 0 8 0xFF AIRFLOW %.0f mass_airflow_max Maximum air flow rate from mass air flow sensor
0x01,0x02 0x51 0 1 0 8 0xFF FUEL_TYPE %.0f fuel_type Fuel type
0x01,0x02 0x52 0 1 0 8 0xFF PERCENT %.0f ethanol_fuel_percentage Ethanol fuel %

Loading…
Cancel
Save