More Externals convertor updates.

git-svn-id: https://svn2.assembla.com/svn/romraider/trunk@340 38686702-15cf-42e4-a595-3071df8bf5ea
This commit is contained in:
Dale Schultz 2011-09-22 20:31:24 +00:00
parent 5955e152c6
commit 0d5229ac91
14 changed files with 223 additions and 66 deletions

View File

@ -20,21 +20,16 @@
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.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 units;
private final String expression; private final String expression;
private final GaugeMinMax gaugeMinMax; private final GaugeMinMax gaugeMinMax = new GaugeMinMax(0,0,0);
private final ExternalDataItem dataItem; private final ExternalDataItem dataItem;
private DecimalFormat format; private DecimalFormat format;
@ -43,16 +38,19 @@ public final class ExternalDataConvertorImpl implements EcuDataConvertor {
// <conversion units="hPa" expr="x*37/255/14.50377*1000" format="0" gauge_min="-1200" gauge_max="2800" gauge_step="400" /> // <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" /> // <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, String units, String expression,
String format
// GaugeMinMax gaugeMinMax
) {
this.dataItem = dataItem; this.dataItem = dataItem;
this.units = dataItem.getUnits(); this.units = units;
this.expression = "x"; this.expression = expression;
this.gaugeMinMax = new GaugeMinMax(0,0,0); this.format = new DecimalFormat(format);
this.format = new DecimalFormat("0.##");
} }
public double convert(byte[] bytes) { public double convert(byte[] bytes) {
double value = dataItem.getData(); double value = dataItem.getData();
// int value = asUnsignedInt(bytes);
double result = evaluate(expression, value); double result = evaluate(expression, value);
return Double.isNaN(result) || Double.isInfinite(result) ? 0.0 : result; return Double.isNaN(result) || Double.isInfinite(result) ? 0.0 : result;
} }
@ -72,4 +70,8 @@ public final class ExternalDataConvertorImpl implements EcuDataConvertor {
public String getFormat() { public String getFormat() {
return format.toPattern(); return format.toPattern();
} }
public String toString() {
return getUnits();
}
} }

View File

@ -40,8 +40,7 @@ public final class ExternalDataImpl implements ExternalData {
public ExternalDataImpl(final ExternalDataItem dataItem, ExternalDataSource dataSource) { public ExternalDataImpl(final ExternalDataItem dataItem, ExternalDataSource dataSource) {
checkNotNull(dataItem, dataSource); checkNotNull(dataItem, dataSource);
this.dataSource = dataSource; this.dataSource = dataSource;
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(dataItem)}; this.convertors = dataItem.getConvertors();
this.convertors = convertors;
id = createId(dataItem); id = createId(dataItem);
name = dataItem.getName(); name = dataItem.getName();
description = dataItem.getDescription(); description = dataItem.getDescription();

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.aem.plugin; package com.romraider.logger.external.aem.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
@ -33,9 +35,9 @@ public final class AemDataItem implements ExternalDataItem, DataListener {
return "AEM UEGO AFR data"; return "AEM UEGO AFR data";
} }
public String getUnits() { // public String getUnits() {
return "AFR"; // return "AFR";
} // }
public double getData() { public double getData() {
return data; return data;
@ -44,4 +46,20 @@ public final class AemDataItem implements ExternalDataItem, DataListener {
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String units = "AFR";
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.aem2.plugin; package com.romraider.logger.external.aem2.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
@ -26,16 +28,16 @@ public final class AemDataItem implements ExternalDataItem, DataListener {
private double data; private double data;
public String getName() { public String getName() {
return "AEM UEGO Lambda [19200]"; return "AEM UEGO [19200 baud]";
} }
public String getDescription() { public String getDescription() {
return "AEM UEGO Lambda data"; return "AEM UEGO Wideband data";
} }
public String getUnits() { // public String getUnits() {
return "Lambda"; // return "Lambda";
} // }
public double getData() { public double getData() {
return data; return data;
@ -44,4 +46,20 @@ public final class AemDataItem implements ExternalDataItem, DataListener {
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String units = "Lambda";
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,12 +19,20 @@
package com.romraider.logger.external.core; package com.romraider.logger.external.core;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
public interface ExternalDataItem { public interface ExternalDataItem {
String getName(); String getName();
String getDescription(); String getDescription();
String getUnits(); // String getUnits();
//
// String getFormat();
//
// String getExpression();
double getData(); double getData();
EcuDataConvertor[] getConvertors();
} }

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.fourteenpoint7.plugin; package com.romraider.logger.external.fourteenpoint7.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
import com.romraider.logger.external.core.RawDataListener; import com.romraider.logger.external.core.RawDataListener;
@ -31,12 +33,12 @@ public final class NawDataItem implements ExternalDataItem, RawDataListener {
} }
public String getDescription() { public String getDescription() {
return "14Point7 NAW_7S AFR data"; return "14Point7 NAW_7S Wideband data";
} }
public String getUnits() { // public String getUnits() {
return "AFR"; // return "AFR";
} // }
public double getData() { public double getData() {
if (bytes == null) return 0.0; if (bytes == null) return 0.0;
@ -46,4 +48,20 @@ public final class NawDataItem implements ExternalDataItem, RawDataListener {
public void setBytes(byte[] bytes) { public void setBytes(byte[] bytes) {
this.bytes = bytes; this.bytes = bytes;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String units = "AFR";
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.innovate.generic.serial.plugin; package com.romraider.logger.external.innovate.generic.serial.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
@ -33,9 +35,9 @@ public final class InnovateDataItem implements ExternalDataItem, DataListener {
return "Innovate Wideband AFR data"; return "Innovate Wideband AFR data";
} }
public String getUnits() { // public String getUnits() {
return "AFR"; // return "AFR";
} // }
public double getData() { public double getData() {
return data; return data;
@ -44,4 +46,20 @@ public final class InnovateDataItem implements ExternalDataItem, DataListener {
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String units = "AFR";
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.innovate.lm2.mts.plugin; package com.romraider.logger.external.innovate.lm2.mts.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
@ -33,9 +35,9 @@ public final class Lm2MtsDataItem implements ExternalDataItem, DataListener {
return "Innovate LM-2 AFR data"; return "Innovate LM-2 AFR data";
} }
public String getUnits() { // public String getUnits() {
return "AFR"; // return "AFR";
} // }
public double getData() { public double getData() {
return data; return data;
@ -44,4 +46,20 @@ public final class Lm2MtsDataItem implements ExternalDataItem, DataListener {
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String units = "AFR";
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.mrf.plugin; package com.romraider.logger.external.mrf.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
@ -40,9 +42,9 @@ public final class MrfDataItem implements ExternalDataItem, DataListener {
return "MRF Stealth Gauge " + name + " data"; return "MRF Stealth Gauge " + name + " data";
} }
public String getUnits() { // public String getUnits() {
return units; // return units;
} // }
public double getData() { public double getData() {
return data; return data;
@ -51,4 +53,19 @@ public final class MrfDataItem implements ExternalDataItem, DataListener {
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.plx.plugin; package com.romraider.logger.external.plx.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.plx.io.PlxSensorType; import com.romraider.logger.external.plx.io.PlxSensorType;
import com.romraider.logger.external.plx.io.PlxSensorUnits; import com.romraider.logger.external.plx.io.PlxSensorUnits;
@ -45,9 +47,9 @@ public final class PlxDataItemImpl implements PlxDataItem {
return "PLX " + name + " data"; return "PLX " + name + " data";
} }
public String getUnits() { // public String getUnits() {
return units; // return units;
} // }
public double getData() { public double getData() {
return convertor.convert(raw, sensorType, sensorUnits); return convertor.convert(raw, sensorType, sensorUnits);
@ -56,4 +58,19 @@ public final class PlxDataItemImpl implements PlxDataItem {
public void setRaw(int raw) { public void setRaw(int raw) {
this.raw = raw; this.raw = raw;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -23,8 +23,4 @@ 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

@ -19,27 +19,27 @@
package com.romraider.logger.external.te.plugin; package com.romraider.logger.external.te.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.te.plugin.TESensorUnits; import com.romraider.logger.external.te.plugin.TESensorUnits;
public final class TEDataItemImpl implements TEDataItem { public final class TEDataItemImpl implements TEDataItem {
private final TEConverter converter = new TEConverterImpl(); private final TEConverter converter = new TEConverterImpl();
private final EcuDataConvertor[] convertors;
private final TESensorUnits sensorUnits; private final TESensorUnits sensorUnits;
private final TESensorType sensorType; private final TESensorType sensorType;
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, String expression, String format) {
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.sensorType = sensorType; this.sensorType = sensorType;
this.sensorUnits = sensorUnits; this.sensorUnits = sensorUnits;
this.format = format; convertors = new EcuDataConvertor[] {
this.expression = expression; new ExternalDataConvertorImpl(this, units, expression, format)
// new ExternalDataConvertorImpl(this, "foo", "x", "0")
};
} }
public String getName() { public String getName() {
@ -50,16 +50,8 @@ public final class TEDataItemImpl implements TEDataItem {
return "Tech Edge " + name + " data"; return "Tech Edge " + name + " data";
} }
public String getUnits() { public EcuDataConvertor[] getConvertors() {
return units; return convertors;
}
public String getFormat() {
return format;
}
public String getExpression() {
return expression;
} }
public double getData() { public double getData() {

View File

@ -19,6 +19,8 @@
package com.romraider.logger.external.txstuner.plugin; package com.romraider.logger.external.txstuner.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
import com.romraider.logger.external.core.DataListener; import com.romraider.logger.external.core.DataListener;
import com.romraider.logger.external.core.ExternalDataItem; import com.romraider.logger.external.core.ExternalDataItem;
@ -34,9 +36,9 @@ public final class TxsTunerDataItem implements ExternalDataItem, DataListener {
return "TXS Tuner AFR data"; return "TXS Tuner AFR data";
} }
public String getUnits() { // public String getUnits() {
return "AFR"; // return "AFR";
} // }
public double getData() { public double getData() {
return data; return data;
@ -45,5 +47,21 @@ public final class TxsTunerDataItem implements ExternalDataItem, DataListener {
public void setData(double data) { public void setData(double data) {
this.data = data; this.data = data;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String units = "AFR";
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }

View File

@ -19,6 +19,9 @@
package com.romraider.logger.external.zt2.plugin; package com.romraider.logger.external.zt2.plugin;
import com.romraider.logger.ecu.definition.EcuDataConvertor;
import com.romraider.logger.ecu.definition.ExternalDataConvertorImpl;
public final class ZT2DataItemImpl implements ZT2DataItem { public final class ZT2DataItemImpl implements ZT2DataItem {
private final ZT2Converter converter = new ZT2ConverterImpl(); private final ZT2Converter converter = new ZT2ConverterImpl();
private final ZT2SensorType sensorType; private final ZT2SensorType sensorType;
@ -41,9 +44,9 @@ public final class ZT2DataItemImpl implements ZT2DataItem {
return "Zeitronix ZT-2 " + name + " data"; return "Zeitronix ZT-2 " + name + " data";
} }
public String getUnits() { // public String getUnits() {
return units; // return units;
} // }
public double getData() { public double getData() {
return converter.convert(sensorType, raw); return converter.convert(sensorType, raw);
@ -52,4 +55,19 @@ public final class ZT2DataItemImpl implements ZT2DataItem {
public void setRaw(int... raw) { public void setRaw(int... raw) {
this.raw = raw; this.raw = raw;
} }
// public String getFormat() {
// return "0.##";
// }
//
// public String getExpression() {
// return "x";
// }
public EcuDataConvertor[] getConvertors() {
String expression = "x";
String format = "0.##";
EcuDataConvertor[] convertors = {new ExternalDataConvertorImpl(this, units, expression, format)};
return convertors;
}
} }