mirror of https://github.com/rusefi/RomRaider.git
declarative convertors added to logger config file, JEP expression parsing moved into a utility class
git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@243 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
parent
466a0755b3
commit
7b23479b4a
87
logger.xml
87
logger.xml
|
@ -3,52 +3,63 @@
|
|||
<protocols>
|
||||
<protocol id="SSM">
|
||||
<parameters>
|
||||
<parameter id="Coolant Temperature" desc="Engine coolant temperature reading.">
|
||||
<address>
|
||||
<byte>0x000008</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.GenericTemperatureConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="Engine Speed" desc="Engine speed in Revolutions Per Minute.">
|
||||
<address>
|
||||
<byte>0x00000E</byte>
|
||||
<byte>0x00000F</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.EngineSpeedConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="Throttle Opening Angle" desc="Engine throttle opening angle.">
|
||||
<address>
|
||||
<byte>0x000015</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.ThrottleOpeningAngleConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="Accelerator Opening Angle" desc="Accelerator pedal opening angle.">
|
||||
<address>
|
||||
<byte>0x000029</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.AcceleratorOpeningAngleConvertor</convertor>
|
||||
</parameter>
|
||||
<parameter id="EGT" desc="Exhaust gas temperature reading.">
|
||||
<address>
|
||||
<byte>0x000106</byte>
|
||||
</address>
|
||||
<convertor>enginuity.logger.definition.convertor.ExhaustGasTemperatureConvertor</convertor>
|
||||
</parameter>
|
||||
|
||||
<!-- More to come!! -->
|
||||
|
||||
<!-- New format -->
|
||||
<!--
|
||||
<parameter id="Coolant Temperature" desc="Engine coolant temperature reading.">
|
||||
<address>
|
||||
<byte>0x000008</byte>
|
||||
</address>
|
||||
<conversion>
|
||||
<metric units="C" expr=""/>
|
||||
<imperial units="F" expr=""/>
|
||||
<metric units="C" expr="x-40" format="0"/>
|
||||
</conversion>
|
||||
</parameter>
|
||||
-->
|
||||
|
||||
<parameter id="Engine Speed" desc="Engine speed in Revolutions Per Minute.">
|
||||
<address>
|
||||
<byte>0x00000E</byte>
|
||||
<byte>0x00000F</byte>
|
||||
</address>
|
||||
<conversion>
|
||||
<metric units="rpm" expr="x/4" format="0"/>
|
||||
</conversion>
|
||||
</parameter>
|
||||
|
||||
<parameter id="Throttle Opening Angle" desc="Engine throttle opening angle.">
|
||||
<address>
|
||||
<byte>0x000015</byte>
|
||||
</address>
|
||||
<conversion>
|
||||
<metric units="%" expr="x/2.55" format="0.0"/>
|
||||
</conversion>
|
||||
</parameter>
|
||||
|
||||
<parameter id="Accelerator Pedal Angle" desc="Accelerator pedal angle.">
|
||||
<address>
|
||||
<byte>0x000029</byte>
|
||||
</address>
|
||||
<conversion>
|
||||
<metric units="%" expr="x/2.55" format="0.0"/>
|
||||
</conversion>
|
||||
</parameter>
|
||||
|
||||
<parameter id="AFR" desc="Engine air/fuel ratio reading.">
|
||||
<address>
|
||||
<byte>0x000046</byte>
|
||||
</address>
|
||||
<conversion>
|
||||
<metric units="Lambda" expr="x/128" format="0.0"/>
|
||||
</conversion>
|
||||
</parameter>
|
||||
|
||||
<parameter id="EGT" desc="Exhaust gas temperature reading.">
|
||||
<address>
|
||||
<byte>0x000106</byte>
|
||||
</address>
|
||||
<conversion>
|
||||
<metric units="C" expr="(x+40)*5" format="0"/>
|
||||
</conversion>
|
||||
</parameter>
|
||||
|
||||
<!-- More to come!! -->
|
||||
|
||||
</parameters>
|
||||
</protocol>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
package enginuity.logger;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.io.serial.SerialPortDiscoverer;
|
||||
import enginuity.logger.io.serial.SerialPortDiscovererImpl;
|
||||
import enginuity.logger.definition.EcuParameter;
|
||||
import enginuity.logger.manager.QueryManager;
|
||||
import enginuity.logger.manager.QueryManagerImpl;
|
||||
import enginuity.logger.manager.TransmissionManager;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.logger.definition.convertor.EcuParameterConvertor;
|
||||
|
||||
public interface EcuParameter {
|
||||
|
||||
String getName();
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public interface EcuParameterConvertor {
|
||||
|
||||
double convert(byte[] bytes);
|
||||
|
||||
String getUnits();
|
||||
|
||||
String format(double value);
|
||||
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import static enginuity.util.ByteUtil.asInt;
|
||||
import static enginuity.util.JEPUtil.evaluate;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public final class EcuParameterConvertorImpl implements EcuParameterConvertor {
|
||||
private final String units;
|
||||
private final String expression;
|
||||
private final DecimalFormat format;
|
||||
|
||||
public EcuParameterConvertorImpl(String units, String expression, String format) {
|
||||
checkNotNullOrEmpty(units, "units");
|
||||
checkNotNullOrEmpty(expression, "expression");
|
||||
checkNotNullOrEmpty(format, "format");
|
||||
this.units = units;
|
||||
this.expression = expression;
|
||||
this.format = new DecimalFormat(format);
|
||||
}
|
||||
|
||||
public double convert(byte[] bytes) {
|
||||
double value = (double) asInt(bytes);
|
||||
return evaluate(expression, value);
|
||||
}
|
||||
|
||||
public String getUnits() {
|
||||
return units;
|
||||
}
|
||||
|
||||
public String format(double value) {
|
||||
return format.format(value);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.logger.definition.convertor.EcuParameterConvertor;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
||||
|
||||
|
|
|
@ -5,10 +5,10 @@ import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
|
|||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
import java.io.InputStream;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
public final class EcuParameterLoaderImpl implements EcuParameterLoader {
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public interface LoggerDefinition {
|
||||
}
|
|
@ -1,7 +1,5 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
import enginuity.logger.definition.convertor.EcuParameterConvertor;
|
||||
import enginuity.logger.exception.ConfigurationException;
|
||||
import enginuity.util.ParamChecker;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
@ -15,9 +13,13 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
private static final String TAG_PROTOCOL = "protocol";
|
||||
private static final String TAG_PARAMETER = "parameter";
|
||||
private static final String TAG_CONVERTOR = "convertor";
|
||||
private static final String TAG_METRIC = "metric";
|
||||
private static final String TAG_BYTE = "byte";
|
||||
private static final String ATTR_ID = "id";
|
||||
private static final String ATTR_DESC = "desc";
|
||||
private static final String ATTR_UNITS = "units";
|
||||
private static final String ATTR_EXPRESSION = "expr";
|
||||
private static final String ATTR_FORMAT = "format";
|
||||
private List<EcuParameter> params;
|
||||
private String paramName;
|
||||
private String paramDesc;
|
||||
|
@ -44,6 +46,9 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
paramName = attributes.getValue(ATTR_ID);
|
||||
paramDesc = attributes.getValue(ATTR_DESC);
|
||||
addressList = new ArrayList<String>();
|
||||
} else if (TAG_METRIC.equals(qName)) {
|
||||
convertor = new EcuParameterConvertorImpl(attributes.getValue(ATTR_UNITS), attributes.getValue(ATTR_EXPRESSION),
|
||||
attributes.getValue(ATTR_FORMAT));
|
||||
}
|
||||
}
|
||||
charBuffer = new StringBuilder();
|
||||
|
@ -61,12 +66,6 @@ public final class LoggerDefinitionHandler extends DefaultHandler {
|
|||
} else if (parseProtocol) {
|
||||
if (TAG_BYTE.equals(qName)) {
|
||||
addressList.add(charBuffer.toString());
|
||||
} else if (TAG_CONVERTOR.equals(qName)) {
|
||||
try {
|
||||
convertor = (EcuParameterConvertor) Class.forName(charBuffer.toString().trim()).newInstance();
|
||||
} catch (Exception e) {
|
||||
throw new ConfigurationException(e);
|
||||
}
|
||||
} else if (TAG_PARAMETER.equals(qName)) {
|
||||
String[] addresses = new String[addressList.size()];
|
||||
addressList.toArray(addresses);
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
package enginuity.logger.definition;
|
||||
|
||||
public final class LoggerDefinitionImpl implements LoggerDefinition {
|
||||
}
|
|
@ -7,7 +7,6 @@ import enginuity.logger.exception.UnsupportedPortTypeException;
|
|||
import enginuity.logger.io.serial.protocol.ConnectionProperties;
|
||||
import enginuity.logger.io.serial.protocol.Protocol;
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import enginuity.logger.io.serial.SerialConnection;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
import static enginuity.util.ParamChecker.checkGreaterThanZero;
|
||||
import static enginuity.util.ParamChecker.checkNotNull;
|
||||
|
|
|
@ -8,8 +8,6 @@ import java.util.ArrayList;
|
|||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import enginuity.logger.io.serial.SerialPortDiscoverer;
|
||||
|
||||
public final class SerialPortDiscovererImpl implements SerialPortDiscoverer {
|
||||
|
||||
@SuppressWarnings({"unchecked"})
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package enginuity.logger.io.serial.protocol;
|
||||
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import enginuity.logger.exception.InvalidResponseException;
|
||||
import enginuity.logger.query.RegisteredQuery;
|
||||
import static enginuity.util.ByteUtil.asByte;
|
||||
import static enginuity.util.ByteUtil.asInt;
|
||||
import static enginuity.util.HexUtil.asHex;
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package enginuity.logger.manager;
|
||||
|
||||
import enginuity.Settings;
|
||||
import enginuity.logger.io.serial.SerialConnection;
|
||||
import enginuity.logger.io.serial.SerialConnectionImpl;
|
||||
import enginuity.logger.exception.NotConnectedException;
|
||||
import enginuity.logger.exception.SerialCommunicationException;
|
||||
import enginuity.logger.io.serial.SerialConnection;
|
||||
import enginuity.logger.io.serial.SerialConnectionImpl;
|
||||
import enginuity.logger.io.serial.protocol.Protocol;
|
||||
import enginuity.logger.io.serial.protocol.ProtocolFactory;
|
||||
import enginuity.logger.query.LoggerCallback;
|
||||
|
|
|
@ -1,39 +1,37 @@
|
|||
package enginuity.maps;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Font;
|
||||
import enginuity.util.JEPUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseListener;
|
||||
import java.io.Serializable;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
||||
import org.nfunk.jep.JEP;
|
||||
|
||||
public class DataCell extends JLabel implements MouseListener, Serializable {
|
||||
|
||||
private double binValue = 0;
|
||||
private double originalValue = 0;
|
||||
private Scale scale = new Scale();
|
||||
private String displayValue = "";
|
||||
private double realValue = 0;
|
||||
private Color scaledColor = new Color(0,0,0);
|
||||
private Color highlightColor = new Color(155,155,255);
|
||||
private Color increaseBorder = Color.RED;
|
||||
private Color decreaseBorder = Color.BLUE;
|
||||
private Boolean selected = false;
|
||||
private Boolean highlighted = false;
|
||||
private Table table;
|
||||
private int x = 0;
|
||||
private int y = 0;
|
||||
private double compareValue = 0;
|
||||
private int compareType = Table.COMPARE_OFF;
|
||||
private int compareDisplay = Table.COMPARE_ABSOLUTE;
|
||||
|
||||
public DataCell() { }
|
||||
|
||||
|
||||
private double binValue = 0;
|
||||
private double originalValue = 0;
|
||||
private Scale scale = new Scale();
|
||||
private String displayValue = "";
|
||||
private Color scaledColor = new Color(0, 0, 0);
|
||||
private Color highlightColor = new Color(155, 155, 255);
|
||||
private Color increaseBorder = Color.RED;
|
||||
private Color decreaseBorder = Color.BLUE;
|
||||
private Boolean selected = false;
|
||||
private Boolean highlighted = false;
|
||||
private Table table;
|
||||
private int x = 0;
|
||||
private int y = 0;
|
||||
private double compareValue = 0;
|
||||
private int compareType = Table.COMPARE_OFF;
|
||||
private int compareDisplay = Table.COMPARE_ABSOLUTE;
|
||||
|
||||
public DataCell() {
|
||||
}
|
||||
|
||||
public DataCell(Scale scale) {
|
||||
this.scale = scale;
|
||||
this.setHorizontalAlignment(CENTER);
|
||||
|
@ -44,76 +42,77 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
|
|||
this.setVisible(true);
|
||||
this.addMouseListener(this);
|
||||
}
|
||||
|
||||
|
||||
public void updateDisplayValue() {
|
||||
DecimalFormat formatter = new DecimalFormat(scale.getFormat());
|
||||
|
||||
|
||||
if (getCompareType() == Table.COMPARE_OFF) {
|
||||
displayValue = formatter.format(calcDisplayValue(binValue, table.getScale().getExpression()));
|
||||
|
||||
|
||||
} else {
|
||||
if (getCompareDisplay() == Table.COMPARE_ABSOLUTE) {
|
||||
displayValue = formatter.format(
|
||||
calcDisplayValue(binValue, table.getScale().getExpression()) -
|
||||
calcDisplayValue(compareValue, table.getScale().getExpression()));
|
||||
|
||||
calcDisplayValue(binValue, table.getScale().getExpression()) -
|
||||
calcDisplayValue(compareValue, table.getScale().getExpression()));
|
||||
|
||||
} else if (getCompareDisplay() == Table.COMPARE_PERCENT) {
|
||||
double difference = calcDisplayValue(binValue, table.getScale().getExpression()) -
|
||||
calcDisplayValue(compareValue, table.getScale().getExpression());
|
||||
if (difference == 0) displayValue = "0%";
|
||||
else displayValue = (int)(difference / calcDisplayValue(binValue, table.getScale().getExpression()) * 100)+"%";
|
||||
double difference = calcDisplayValue(binValue, table.getScale().getExpression()) -
|
||||
calcDisplayValue(compareValue, table.getScale().getExpression());
|
||||
if (difference == 0) {
|
||||
displayValue = "0%";
|
||||
} else {
|
||||
displayValue = (int) (difference / calcDisplayValue(binValue, table.getScale().getExpression()) * 100) + "%";
|
||||
}
|
||||
}
|
||||
}
|
||||
setText(displayValue);
|
||||
}
|
||||
|
||||
|
||||
public double calcDisplayValue(double input, String expression) {
|
||||
JEP parser = new JEP();
|
||||
parser.initSymTab(); // clear the contents of the symbol table
|
||||
parser.addVariable("x", input);
|
||||
parser.parseExpression(expression);
|
||||
return parser.getValue();
|
||||
return JEPUtil.evaluate(expression, input);
|
||||
}
|
||||
|
||||
|
||||
public void setColor(Color color) {
|
||||
scaledColor = color;
|
||||
if (!selected) super.setBackground(color);
|
||||
if (!selected) {
|
||||
super.setBackground(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setDisplayValue(String displayValue) {
|
||||
this.displayValue = displayValue;
|
||||
this.setText(displayValue);
|
||||
}
|
||||
|
||||
public void setBinValue(double binValue) {
|
||||
this.binValue = binValue;
|
||||
|
||||
// make sure it's in range
|
||||
if (table.getStorageType() != Table.STORAGE_TYPE_FLOAT) {
|
||||
if (binValue < 0) {
|
||||
this.setBinValue(0);
|
||||
|
||||
} else if (binValue > Math.pow(256, table.getStorageType()) - 1) {
|
||||
this.setBinValue((int)(Math.pow(256, table.getStorageType()) - 1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.updateDisplayValue();
|
||||
}
|
||||
|
||||
public void setBinValue(double binValue) {
|
||||
this.binValue = binValue;
|
||||
|
||||
// make sure it's in range
|
||||
if (table.getStorageType() != Table.STORAGE_TYPE_FLOAT) {
|
||||
if (binValue < 0) {
|
||||
this.setBinValue(0);
|
||||
|
||||
} else if (binValue > Math.pow(256, table.getStorageType()) - 1) {
|
||||
this.setBinValue((int) (Math.pow(256, table.getStorageType()) - 1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
this.updateDisplayValue();
|
||||
}
|
||||
|
||||
public double getBinValue() {
|
||||
return binValue;
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return displayValue;
|
||||
}
|
||||
|
||||
|
||||
public Boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
|
||||
public void setSelected(Boolean selected) {
|
||||
this.selected = selected;
|
||||
if (selected) {
|
||||
|
@ -125,56 +124,64 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
|
|||
}
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
|
||||
public void setHighlighted(Boolean highlighted) {
|
||||
if (!table.isStatic()) {
|
||||
this.highlighted = highlighted;
|
||||
if (highlighted) {
|
||||
this.setBackground(getHighlightColor());
|
||||
} else {
|
||||
if (!selected) this.setBackground(scaledColor);
|
||||
if (!selected) {
|
||||
this.setBackground(scaledColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean isHighlighted() {
|
||||
return highlighted;
|
||||
}
|
||||
|
||||
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
table.highlight(x, y);
|
||||
}
|
||||
|
||||
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (!table.isStatic()) {
|
||||
if (!e.isControlDown()) table.clearSelection();
|
||||
if (!e.isControlDown()) {
|
||||
table.clearSelection();
|
||||
}
|
||||
table.startHighlight(x, y);
|
||||
}
|
||||
requestFocus();
|
||||
}
|
||||
|
||||
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (!table.isStatic()) {
|
||||
table.stopHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
public void mouseClicked(MouseEvent e) { }
|
||||
public void mouseExited(MouseEvent e) { }
|
||||
|
||||
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void mouseExited(MouseEvent e) {
|
||||
}
|
||||
|
||||
public void increment(double increment) {
|
||||
double oldValue = Double.parseDouble(getText());
|
||||
|
||||
if (table.getScale().getCoarseIncrement() < 0) increment = 0 - increment;
|
||||
if (table.getScale().getCoarseIncrement() < 0) {
|
||||
increment = 0 - increment;
|
||||
}
|
||||
|
||||
setRealValue((calcDisplayValue(binValue,
|
||||
scale.getExpression()) + increment) + "");
|
||||
setRealValue(String.valueOf((calcDisplayValue(binValue, scale.getExpression()) + increment)));
|
||||
|
||||
// make sure table is incremented if change isnt great enough
|
||||
int maxValue = (int)Math.pow(8, (double)table.getStorageType());
|
||||
|
||||
int maxValue = (int) Math.pow(8, (double) table.getStorageType());
|
||||
|
||||
if (table.getStorageType() != Table.STORAGE_TYPE_FLOAT &&
|
||||
oldValue == Double.parseDouble(getText()) &&
|
||||
oldValue == Double.parseDouble(getText()) &&
|
||||
binValue > 0 &&
|
||||
binValue < maxValue) {
|
||||
System.out.println(maxValue + " " + binValue);
|
||||
|
@ -183,25 +190,25 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
|
|||
}
|
||||
|
||||
table.colorize();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void setTable(Table table) {
|
||||
this.table = table;
|
||||
}
|
||||
|
||||
|
||||
public void setXCoord(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
|
||||
public void setYCoord(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
|
||||
public double getOriginalValue() {
|
||||
return originalValue;
|
||||
}
|
||||
|
||||
|
||||
public void setOriginalValue(double originalValue) {
|
||||
this.originalValue = originalValue;
|
||||
if (binValue != getOriginalValue()) {
|
||||
|
@ -210,37 +217,34 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
|
|||
this.setBorder(new LineBorder(Color.BLACK, 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void undo() {
|
||||
this.setBinValue(originalValue);
|
||||
}
|
||||
|
||||
|
||||
public void setRevertPoint() {
|
||||
this.setOriginalValue(binValue);
|
||||
}
|
||||
|
||||
|
||||
public void setRealValue(String input) {
|
||||
// create parser
|
||||
if (!input.equalsIgnoreCase("x")) {
|
||||
JEP parser = new JEP();
|
||||
parser.initSymTab(); // clear the contents of the symbol table
|
||||
parser.addVariable("x", Double.parseDouble(input));
|
||||
parser.parseExpression(table.getScale().getByteExpression());
|
||||
|
||||
if (!"x".equalsIgnoreCase(input)) {
|
||||
double result = JEPUtil.evaluate(table.getScale().getByteExpression(), Double.parseDouble(input));
|
||||
|
||||
if (table.getStorageType() == Table.STORAGE_TYPE_FLOAT) {
|
||||
this.setBinValue(parser.getValue());
|
||||
|
||||
this.setBinValue(result);
|
||||
|
||||
} else {
|
||||
this.setBinValue((int)Math.round(parser.getValue()));
|
||||
|
||||
this.setBinValue((int) Math.round(result));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public Color getHighlightColor() {
|
||||
return highlightColor;
|
||||
}
|
||||
|
||||
|
||||
public void setHighlightColor(Color highlightColor) {
|
||||
this.highlightColor = highlightColor;
|
||||
}
|
||||
|
@ -280,32 +284,28 @@ public class DataCell extends JLabel implements MouseListener, Serializable {
|
|||
public int getCompareDisplay() {
|
||||
return compareDisplay;
|
||||
}
|
||||
|
||||
|
||||
public void setCompareRealValue(String input) {
|
||||
JEP parser = new JEP();
|
||||
parser.initSymTab(); // clear the contents of the symbol table
|
||||
parser.addVariable("x", Double.parseDouble(input));
|
||||
parser.parseExpression(table.getScale().getByteExpression());
|
||||
this.setCompareValue((int)Math.round(parser.getValue()));
|
||||
double result = JEPUtil.evaluate(table.getScale().getByteExpression(), Double.parseDouble(input));
|
||||
this.setCompareValue((int) Math.round(result));
|
||||
}
|
||||
|
||||
public void setCompareDisplay(int compareDisplay) {
|
||||
this.compareDisplay = compareDisplay;
|
||||
}
|
||||
|
||||
|
||||
public void refreshValue() {
|
||||
setBinValue(binValue);
|
||||
}
|
||||
|
||||
|
||||
public void multiply(double factor) {
|
||||
setRealValue(Double.parseDouble(getText()) * factor+"");
|
||||
setRealValue(String.valueOf(Double.parseDouble(getText()) * factor));
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by 3d graph renderer.
|
||||
* @return
|
||||
*/
|
||||
public double getValue() {
|
||||
return calcDisplayValue(binValue, table.getScale().getExpression());
|
||||
}
|
||||
public double getValue() {
|
||||
return calcDisplayValue(binValue, table.getScale().getExpression());
|
||||
}
|
||||
}
|
|
@ -3,8 +3,8 @@ package enginuity.maps;
|
|||
import enginuity.Settings;
|
||||
import enginuity.swing.TableFrame;
|
||||
import static enginuity.util.ColorScaler.getScaledColor;
|
||||
import enginuity.util.JEPUtil;
|
||||
import enginuity.xml.RomAttributeParser;
|
||||
import org.nfunk.jep.JEP;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.LineBorder;
|
||||
|
@ -22,66 +22,66 @@ import java.util.StringTokenizer;
|
|||
import java.util.Vector;
|
||||
|
||||
public abstract class Table extends JPanel implements Serializable {
|
||||
|
||||
public static final int ENDIAN_LITTLE= 1;
|
||||
public static final int ENDIAN_BIG = 2;
|
||||
|
||||
public static final int TABLE_1D = 1;
|
||||
public static final int TABLE_2D = 2;
|
||||
public static final int TABLE_3D = 3;
|
||||
|
||||
public static final int ENDIAN_LITTLE = 1;
|
||||
public static final int ENDIAN_BIG = 2;
|
||||
|
||||
public static final int TABLE_1D = 1;
|
||||
public static final int TABLE_2D = 2;
|
||||
public static final int TABLE_3D = 3;
|
||||
public static final int TABLE_X_AXIS = 4;
|
||||
public static final int TABLE_Y_AXIS = 5;
|
||||
public static final int TABLE_SWITCH = 6;
|
||||
|
||||
public static final int COMPARE_OFF = 0;
|
||||
|
||||
public static final int COMPARE_OFF = 0;
|
||||
public static final int COMPARE_ORIGINAL = 1;
|
||||
public static final int COMPARE_TABLE = 2;
|
||||
public static final int COMPARE_PERCENT = 0;
|
||||
public static final int COMPARE_TABLE = 2;
|
||||
public static final int COMPARE_PERCENT = 0;
|
||||
public static final int COMPARE_ABSOLUTE = 1;
|
||||
|
||||
|
||||
public static final int STORAGE_TYPE_FLOAT = 99;
|
||||
|
||||
protected static final Color UNCHANGED_VALUE_COLOR = new Color(160, 160, 160);
|
||||
|
||||
protected String name;
|
||||
protected int type;
|
||||
protected String category = "Other";
|
||||
protected String description = "";
|
||||
protected Vector<Scale> scales = new Vector<Scale>();
|
||||
protected int scaleIndex = 0; // index of selected scale
|
||||
|
||||
protected int storageAddress;
|
||||
protected int storageType;
|
||||
protected int endian;
|
||||
protected boolean flip;
|
||||
protected DataCell[] data = new DataCell[0];
|
||||
protected boolean isStatic = false;
|
||||
protected boolean beforeRam = false;
|
||||
protected int ramOffset = 0;
|
||||
protected BorderLayout borderLayout = new BorderLayout();
|
||||
protected GridLayout centerLayout = new GridLayout(1,1,0,0);
|
||||
protected JPanel centerPanel = new JPanel(centerLayout);
|
||||
protected TableFrame frame;
|
||||
protected int verticalOverhead = 103;
|
||||
protected int horizontalOverhead = 2;
|
||||
protected int cellHeight = 18;
|
||||
protected int cellWidth = 42;
|
||||
protected int minHeight = 100;
|
||||
protected int minWidth = 425;
|
||||
protected Rom container;
|
||||
protected int highlightX;
|
||||
protected int highlightY;
|
||||
protected boolean highlight = false;
|
||||
protected Table axisParent;
|
||||
protected Color maxColor;
|
||||
protected Color minColor;
|
||||
protected boolean isAxis = false;
|
||||
protected int compareType = 0;
|
||||
protected int compareDisplay = 1;
|
||||
protected int userLevel = 0;
|
||||
protected Settings settings;
|
||||
protected boolean locked = false;
|
||||
|
||||
|
||||
protected String name;
|
||||
protected int type;
|
||||
protected String category = "Other";
|
||||
protected String description = "";
|
||||
protected Vector<Scale> scales = new Vector<Scale>();
|
||||
protected int scaleIndex = 0; // index of selected scale
|
||||
|
||||
protected int storageAddress;
|
||||
protected int storageType;
|
||||
protected int endian;
|
||||
protected boolean flip;
|
||||
protected DataCell[] data = new DataCell[0];
|
||||
protected boolean isStatic = false;
|
||||
protected boolean beforeRam = false;
|
||||
protected int ramOffset = 0;
|
||||
protected BorderLayout borderLayout = new BorderLayout();
|
||||
protected GridLayout centerLayout = new GridLayout(1, 1, 0, 0);
|
||||
protected JPanel centerPanel = new JPanel(centerLayout);
|
||||
protected TableFrame frame;
|
||||
protected int verticalOverhead = 103;
|
||||
protected int horizontalOverhead = 2;
|
||||
protected int cellHeight = 18;
|
||||
protected int cellWidth = 42;
|
||||
protected int minHeight = 100;
|
||||
protected int minWidth = 425;
|
||||
protected Rom container;
|
||||
protected int highlightX;
|
||||
protected int highlightY;
|
||||
protected boolean highlight = false;
|
||||
protected Table axisParent;
|
||||
protected Color maxColor;
|
||||
protected Color minColor;
|
||||
protected boolean isAxis = false;
|
||||
protected int compareType = 0;
|
||||
protected int compareDisplay = 1;
|
||||
protected int userLevel = 0;
|
||||
protected Settings settings;
|
||||
protected boolean locked = false;
|
||||
|
||||
public Table(Settings settings) {
|
||||
this.setSettings(settings);
|
||||
this.setLayout(borderLayout);
|
||||
|
@ -225,7 +225,7 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
KeyStroke num7 = KeyStroke.getKeyStroke('7');
|
||||
KeyStroke num8 = KeyStroke.getKeyStroke('8');
|
||||
KeyStroke num9 = KeyStroke.getKeyStroke('9');
|
||||
KeyStroke mulKey = KeyStroke.getKeyStroke('*');
|
||||
KeyStroke mulKey = KeyStroke.getKeyStroke('*');
|
||||
KeyStroke mulKeys = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.CTRL_DOWN_MASK);
|
||||
KeyStroke numPoint = KeyStroke.getKeyStroke('.');
|
||||
KeyStroke copy = KeyStroke.getKeyStroke("control C");
|
||||
|
@ -302,11 +302,11 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
if (scales.isEmpty()) {
|
||||
scales.add(new Scale());
|
||||
}
|
||||
|
||||
|
||||
// temporarily remove lock
|
||||
boolean tempLock = locked;
|
||||
locked = false;
|
||||
|
||||
|
||||
if (!isStatic) {
|
||||
if (!beforeRam) {
|
||||
ramOffset = container.getRomID().getRamOffset();
|
||||
|
@ -325,7 +325,7 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
byteValue[2] = input[storageAddress + i * 4 - ramOffset + 2];
|
||||
byteValue[3] = input[storageAddress + i * 4 - ramOffset + 3];
|
||||
data[i].setBinValue(RomAttributeParser.byteToFloat(byteValue, endian));
|
||||
|
||||
|
||||
} else { // integer storage type
|
||||
data[i].setBinValue(
|
||||
RomAttributeParser.parseByteValue(input,
|
||||
|
@ -338,15 +338,15 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
centerPanel.add(data[i]);
|
||||
data[i].setYCoord(i);
|
||||
data[i].setOriginalValue(data[i].getBinValue());
|
||||
|
||||
|
||||
// show locked cell
|
||||
if (tempLock) {
|
||||
data[i].setForeground(Color.GRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// reset locked status
|
||||
locked = tempLock;
|
||||
}
|
||||
|
@ -499,48 +499,47 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
public void colorize() {
|
||||
if (compareType == COMPARE_OFF) {
|
||||
if (!isStatic && !isAxis) {
|
||||
|
||||
|
||||
double high = Double.MIN_VALUE;
|
||||
double low = Double.MAX_VALUE;
|
||||
|
||||
|
||||
if (getScale().getMax() != 0 || getScale().getMin() != 0) {
|
||||
|
||||
// set min and max values if they are set in scale
|
||||
high = getScale().getMax();
|
||||
low = getScale().getMin();
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
for (int i = 0; i < getDataSize(); i++) {
|
||||
|
||||
if (Double.parseDouble(data[i].getText()) > high) {
|
||||
high = Double.parseDouble(data[i].getText());
|
||||
}
|
||||
}
|
||||
if (Double.parseDouble(data[i].getText()) < low) {
|
||||
low = Double.parseDouble(data[i].getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < getDataSize(); i++) {
|
||||
|
||||
|
||||
if (Double.parseDouble(data[i].getText()) > high ||
|
||||
Double.parseDouble(data[i].getText()) < low) {
|
||||
|
||||
|
||||
// value exceeds limit
|
||||
data[i].setColor(getSettings().getWarningColor());
|
||||
|
||||
} else {
|
||||
data[i].setColor(getSettings().getWarningColor());
|
||||
|
||||
} else {
|
||||
// limits not set, scale based on table values
|
||||
double scale = 0;
|
||||
|
||||
double scale;
|
||||
if (high - low == 0) {
|
||||
// if all values are the same, color will be middle value
|
||||
scale = .5;
|
||||
scale = .5;
|
||||
} else {
|
||||
scale = (Double.parseDouble(data[i].getText()) - low) / (high - low);
|
||||
scale = (Double.parseDouble(data[i].getText()) - low) / (high - low);
|
||||
}
|
||||
|
||||
|
||||
data[i].setColor(getScaledColor(scale, getSettings()));
|
||||
}
|
||||
}
|
||||
|
@ -636,7 +635,7 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void multiply(double factor) {
|
||||
if (!isStatic && !locked) {
|
||||
for (DataCell cell : data) {
|
||||
|
@ -646,9 +645,9 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
}
|
||||
}
|
||||
colorize();
|
||||
}
|
||||
}
|
||||
|
||||
public void setRealValue(String realValue) {
|
||||
public void setRealValue(String realValue) {
|
||||
if (!isStatic && !locked) {
|
||||
for (DataCell cell : data) {
|
||||
if (cell.isSelected()) {
|
||||
|
@ -957,7 +956,7 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
|
||||
public void applyColorSettings(Settings settings) {
|
||||
this.setSettings(settings);
|
||||
|
||||
|
||||
// apply settings to cells
|
||||
for (int i = 0; i < getDataSize(); i++) {
|
||||
this.setMaxColor(settings.getMaxColor());
|
||||
|
@ -998,23 +997,18 @@ public abstract class Table extends JPanel implements Serializable {
|
|||
|
||||
public void validateScaling() {
|
||||
if (type != Table.TABLE_SWITCH && !isStatic) {
|
||||
JEP parser = new JEP();
|
||||
parser.initSymTab(); // clear the contents of the symbol table
|
||||
parser.addVariable("x", 5);
|
||||
|
||||
// make sure a scale is present
|
||||
if (scales.isEmpty()) {
|
||||
scales.add(new Scale());
|
||||
}
|
||||
|
||||
parser.parseExpression(scales.get(scaleIndex).getExpression());
|
||||
double toReal = parser.getValue(); // calculate real world value of "5"
|
||||
|
||||
parser.addVariable("x", toReal);
|
||||
parser.parseExpression(scales.get(scaleIndex).getByteExpression());
|
||||
double startValue = 5;
|
||||
double toReal = JEPUtil.evaluate(scales.get(scaleIndex).getExpression(), startValue); // calculate real world value of "5"
|
||||
double endValue = JEPUtil.evaluate(scales.get(scaleIndex).getByteExpression(), toReal);
|
||||
|
||||
// if real to byte doesn't equal 5, report conflict
|
||||
if (Math.abs(parser.getValue() - 5) > .001) {
|
||||
if (Math.abs(endValue - startValue) > .001) {
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new GridLayout(4, 1));
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package enginuity.util;
|
||||
|
||||
import org.nfunk.jep.JEP;
|
||||
|
||||
public final class JEPUtil {
|
||||
|
||||
private JEPUtil() {
|
||||
}
|
||||
|
||||
public static double evaluate(String expression, double value) {
|
||||
JEP parser = new JEP();
|
||||
parser.initSymTab(); // clear the contents of the symbol table
|
||||
parser.addVariable("x", value);
|
||||
parser.parseExpression(expression);
|
||||
return parser.getValue();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue