More External data converter code

git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@339 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
Dale Schultz 2011-09-22 03:21:36 +00:00
parent 4f35e04fb9
commit 5955e152c6
7 changed files with 76 additions and 23 deletions

View File

@ -34,12 +34,12 @@ documentation may be incomplete or out of date.
------------------------------- -------------------------------
- 0.5.3b RC10 Notes (09/12/2011) - - 0.5.3b RC11 Notes (??/??/????) -
------------------------------- -------------------------------
This is the tenth beta release of the upcoming official 0.5.3b release. This is the eleventh beta release of the upcoming official 0.5.3b release.
--------------------------- ---------------------------
- 0.5.3b RC10 Known Issues - - 0.5.3b RC11 Known Issues -
--------------------------- ---------------------------
- Editor - Editor
- Pasting table data can cause hangs under certain circumstances - Pasting table data can cause hangs under certain circumstances
@ -55,6 +55,15 @@ This is the tenth beta release of the upcoming official 0.5.3b release.
- Change Log - - Change Log -
-------------- --------------
0.5.3b RC11 (??/??/????)
-----------------------
--- Logger ---
- TXS Tuner Wideband plugin added curtosy of, nitros
- Added support for ECU/TCU Switch filtering
- Added (msec) designation to logged CSV column heading
- Added support for sorting the Selected? & Description paramater list entries.
0.5.3b RC10 (09/12/2011) 0.5.3b RC10 (09/12/2011)
----------------------- -----------------------

View File

@ -627,7 +627,6 @@ public final class EcuLogger extends AbstractFrame implements MessageListener {
for (ExternalDataSource dataSource : externalDataSources) { for (ExternalDataSource dataSource : externalDataSources) {
try { try {
List<? extends ExternalDataItem> dataItems = dataSource.getDataItems(); List<? extends ExternalDataItem> dataItems = dataSource.getDataItems();
for (ExternalDataItem item : dataItems) { for (ExternalDataItem item : dataItems) {
externalDatas.add(new ExternalDataImpl(item, dataSource)); externalDatas.add(new ExternalDataImpl(item, dataSource));
} }

View File

@ -20,23 +20,41 @@
package com.romraider.logger.ecu.definition; package com.romraider.logger.ecu.definition;
import static com.romraider.logger.ecu.definition.xml.ConverterMaxMinDefaults.getMaxMin; import static com.romraider.logger.ecu.definition.xml.ConverterMaxMinDefaults.getMaxMin;
import static com.romraider.util.ByteUtil.asUnsignedInt;
import static com.romraider.util.JEPUtil.evaluate;
import static com.romraider.util.ParamChecker.isValidBit;
import static java.lang.Float.intBitsToFloat;
import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax; import com.romraider.logger.ecu.ui.handler.dash.GaugeMinMax;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.Map;
public final class ExternalDataConvertorImpl implements EcuDataConvertor { public final class ExternalDataConvertorImpl implements EcuDataConvertor {
private final String units;
private final String expression;
private final GaugeMinMax gaugeMinMax;
private final ExternalDataItem dataItem; private final ExternalDataItem dataItem;
private static final String FORMAT = "0.##"; private DecimalFormat format;
private DecimalFormat format = new DecimalFormat(FORMAT);
// <conversion units="psi" expr="x*37/255" format="0.00" gauge_min="-20" gauge_max="40" gauge_step="5" />
// <conversion units="kPa" expr="x*37/255/14.50377*100" format="0" gauge_min="-120" gauge_max="280" gauge_step="40" />
// <conversion units="hPa" expr="x*37/255/14.50377*1000" format="0" gauge_min="-1200" gauge_max="2800" gauge_step="400" />
// <conversion units="bar" expr="x*37/255/14.50377" format="0.000" gauge_min="-1.2" gauge_max="2.8" gauge_step="0.4" />
public ExternalDataConvertorImpl(ExternalDataItem dataItem) { public ExternalDataConvertorImpl(ExternalDataItem dataItem) {
this.dataItem = dataItem; this.dataItem = dataItem;
this.units = dataItem.getUnits();
this.expression = "x";
this.gaugeMinMax = new GaugeMinMax(0,0,0);
this.format = new DecimalFormat("0.##");
} }
public double convert(byte[] bytes) { public double convert(byte[] bytes) {
return dataItem.getData(); double value = dataItem.getData();
double result = evaluate(expression, value);
return Double.isNaN(result) || Double.isInfinite(result) ? 0.0 : result;
} }
public String format(double value) { public String format(double value) {
@ -44,7 +62,7 @@ public final class ExternalDataConvertorImpl implements EcuDataConvertor {
} }
public String getUnits() { public String getUnits() {
return dataItem.getUnits(); return units;
} }
public GaugeMinMax getGaugeMinMax() { public GaugeMinMax getGaugeMinMax() {
@ -52,6 +70,6 @@ public final class ExternalDataConvertorImpl implements EcuDataConvertor {
} }
public String getFormat() { public String getFormat() {
return FORMAT; return format.toPattern();
} }
} }

View File

@ -38,7 +38,7 @@ public final class ExternalDataSourceLoaderImpl implements ExternalDataSourceLoa
try { try {
File pluginsDir = new File("./plugins"); File pluginsDir = new File("./plugins");
if (pluginsDir.exists() && pluginsDir.isDirectory()) { if (pluginsDir.exists() && pluginsDir.isDirectory()) {
externalDataSources = new ArrayList<ExternalDataSource>(); // externalDataSources = new ArrayList<ExternalDataSource>();
File[] pluginPropertyFiles = pluginsDir.listFiles(new PluginFilenameFilter()); File[] pluginPropertyFiles = pluginsDir.listFiles(new PluginFilenameFilter());
for (File pluginPropertyFile : pluginPropertyFiles) { for (File pluginPropertyFile : pluginPropertyFiles) {
Properties pluginProps = new Properties(); Properties pluginProps = new Properties();

View File

@ -23,4 +23,8 @@ import com.romraider.logger.external.core.ExternalDataItem;
public interface TEDataItem extends ExternalDataItem { public interface TEDataItem extends ExternalDataItem {
void setRaw(int... raw); void setRaw(int... raw);
String getFormat();
String getExpression();
} }

View File

@ -25,16 +25,21 @@ public final class TEDataItemImpl implements TEDataItem {
private final TEConverter converter = new TEConverterImpl(); private final TEConverter converter = new TEConverterImpl();
private final TESensorUnits sensorUnits; private final TESensorUnits sensorUnits;
private final TESensorType sensorType; private final TESensorType sensorType;
private final String[] units; private final String units;
private final String name; private final String name;
private final String format;
private final String expression;
private int[] raw; private int[] raw;
public TEDataItemImpl(String name, String[] units, TESensorType sensorType, TESensorUnits sensorUnits) { // public TEDataItemImpl(String name, String[] units, TESensorType sensorType, TESensorUnits sensorUnits) {
public TEDataItemImpl(String name, String units, TESensorType sensorType, TESensorUnits sensorUnits, String format, String expression) {
super(); super();
this.name = name; this.name = name;
this.units = units; this.units = units;
this.sensorType = sensorType; this.sensorType = sensorType;
this.sensorUnits = sensorUnits; this.sensorUnits = sensorUnits;
this.format = format;
this.expression = expression;
} }
public String getName() { public String getName() {
@ -46,7 +51,15 @@ public final class TEDataItemImpl implements TEDataItem {
} }
public String getUnits() { public String getUnits() {
return units[0]; return units;
}
public String getFormat() {
return format;
}
public String getExpression() {
return expression;
} }
public double getData() { public double getData() {

View File

@ -52,16 +52,26 @@ public final class TEDataSource implements ExternalDataSource {
private String port; private String port;
{ {
dataItems.put(Lambda, new TEDataItemImpl("Wideband", new String[]{"Lambda", "AFR"}, Lambda, WIDEBAND_AFR_LAMBDA)); // dataItems.put(Lambda, new TEDataItemImpl("Wideband", new String[]{"Lambda", "AFR"}, Lambda, WIDEBAND_AFR_LAMBDA));
dataItems.put(AFR, new TEDataItemImpl("Wideband", new String[]{"AFR"}, Lambda, WIDEBAND_AFR_GASOLINE147)); // dataItems.put(AFR, new TEDataItemImpl("Wideband", new String[]{"AFR"}, Lambda, WIDEBAND_AFR_GASOLINE147));
dataItems.put(USR1, new TEDataItemImpl("User 1", new String[]{"VDC"}, USR1, VDC)); // dataItems.put(USR1, new TEDataItemImpl("User 1", new String[]{"VDC"}, USR1, VDC));
dataItems.put(USR2, new TEDataItemImpl("User 2", new String[]{"VDC"}, USR2, VDC)); // dataItems.put(USR2, new TEDataItemImpl("User 2", new String[]{"VDC"}, USR2, VDC));
dataItems.put(USR3, new TEDataItemImpl("User 3", new String[]{"VDC"}, USR3, VDC)); // dataItems.put(USR3, new TEDataItemImpl("User 3", new String[]{"VDC"}, USR3, VDC));
dataItems.put(TC1, new TEDataItemImpl("Thermocouple 1", new String[]{"raw"}, TC1, RAW)); // dataItems.put(TC1, new TEDataItemImpl("Thermocouple 1", new String[]{"raw"}, TC1, RAW));
dataItems.put(TC2, new TEDataItemImpl("Thermocouple 2", new String[]{"raw"}, TC2, RAW)); // dataItems.put(TC2, new TEDataItemImpl("Thermocouple 2", new String[]{"raw"}, TC2, RAW));
dataItems.put(TC3, new TEDataItemImpl("Thermocouple 3", new String[]{"raw"}, TC3, RAW)); // dataItems.put(TC3, new TEDataItemImpl("Thermocouple 3", new String[]{"raw"}, TC3, RAW));
dataItems.put(TorVss, new TEDataItemImpl("Thermistor or Vss", new String[]{"raw"}, TorVss, RAW)); // dataItems.put(TorVss, new TEDataItemImpl("Thermistor or Vss", new String[]{"raw"}, TorVss, RAW));
dataItems.put(RPM, new TEDataItemImpl("Engine Speed (4-cyl)", new String[]{"RPM"}, RPM, ENGINE_SPEED)); // dataItems.put(RPM, new TEDataItemImpl("Engine Speed (4-cyl)", new String[]{"RPM"}, RPM, ENGINE_SPEED));
dataItems.put(Lambda, new TEDataItemImpl("Wideband", "Lambda", Lambda, WIDEBAND_AFR_LAMBDA, "x", "0.##"));
dataItems.put(AFR, new TEDataItemImpl("Wideband", "AFR", Lambda, WIDEBAND_AFR_GASOLINE147, "x", "0.##"));
dataItems.put(USR1, new TEDataItemImpl("User 1", "VDC", USR1, VDC, "x", "0.##"));
dataItems.put(USR2, new TEDataItemImpl("User 2", "VDC", USR2, VDC, "x", "0.##"));
dataItems.put(USR3, new TEDataItemImpl("User 3", "VDC", USR3, VDC, "x", "0.##"));
dataItems.put(TC1, new TEDataItemImpl("Thermocouple 1", "raw", TC1, RAW, "x", "0.##"));
dataItems.put(TC2, new TEDataItemImpl("Thermocouple 2", "raw", TC2, RAW, "x", "0.##"));
dataItems.put(TC3, new TEDataItemImpl("Thermocouple 3", "raw", TC3, RAW, "x", "0.##"));
dataItems.put(TorVss, new TEDataItemImpl("Thermistor or Vss", "raw", TorVss, RAW, "x", "0.##"));
dataItems.put(RPM, new TEDataItemImpl("Engine Speed (4-cyl)", "RPM", RPM, ENGINE_SPEED, "x", "0.##"));
} }
public String getId() { public String getId() {