Renamed asInt to asUnsignedInt in preparation for new data types

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@462 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Jared Gould 2007-01-22 22:55:46 +00:00
parent 9fe66984e7
commit 634769701f
4 changed files with 127 additions and 12 deletions

View File

@ -21,7 +21,7 @@
package enginuity.logger.definition; package enginuity.logger.definition;
import static enginuity.util.ByteUtil.asInt; import static enginuity.util.ByteUtil.asUnsignedInt;
import static enginuity.util.JEPUtil.evaluate; import static enginuity.util.JEPUtil.evaluate;
import static enginuity.util.ParamChecker.checkNotNullOrEmpty; import static enginuity.util.ParamChecker.checkNotNullOrEmpty;
@ -49,7 +49,7 @@ public final class EcuParameterConvertorImpl implements EcuDataConvertor {
} }
public double convert(byte[] bytes) { public double convert(byte[] bytes) {
double value = (double) (isFloat ? intBitsToFloat(asInt(bytes)) : asInt(bytes)); double value = (double) (isFloat ? intBitsToFloat(asUnsignedInt(bytes)) : 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;
} }

View File

@ -21,25 +21,28 @@
package enginuity.newmaps.gui; package enginuity.newmaps.gui;
import enginuity.newmaps.ecumetadata.Axis;
import enginuity.newmaps.ecumetadata.Scale;
import enginuity.newmaps.ecumetadata.TableMetadata; import enginuity.newmaps.ecumetadata.TableMetadata;
import enginuity.newmaps.ecumetadata.Table3D; import enginuity.newmaps.ecumetadata.Table3D;
import enginuity.newmaps.ecumetadata.Unit;
import javax.swing.JScrollPane; import javax.swing.JScrollPane;
public class Frame3D extends EnginuityFrame { public class Frame3D extends EnginuityFrame {
EnginuityJTable xAxis; EnginuityJTable xAxisTable;
EnginuityJTable yAxis; EnginuityJTable yAxisTable;
EnginuityJTable table; EnginuityJTable table;
public Frame3D(byte[] data, Table3D metadata) { public Frame3D(byte[] data, Table3D metadata) {
super(data, (TableMetadata)metadata); super(data, (TableMetadata)metadata);
table = new EnginuityJTable(1, 1); table = new EnginuityJTable(5, 5);
for (int i = 0; i < 100; i++) for (int i = 0; i < 5; i++)
for (int j = 0; j < 20; j++) for (int j = 0; j < 5; j++)
{ {
table.setValueAt(new Integer(i+j), i, j); table.setValueAt(new Integer(i+j), i, j);
} }
@ -50,13 +53,99 @@ public class Frame3D extends EnginuityFrame {
} }
private void populateTable(byte[] data) {
//
// Do table first..
//
}
//
// Test driver
//
public static void main(String[] args) { public static void main(String[] args) {
/*Frame3D frame = new Frame3D(); byte[] data = new byte[100];
for (int i = 0; i < data.length; i++) {
data[i] = (byte)i;
}
//
// Create table and axis
//
Table3D table = new Table3D("Test");
table.setDescription("This is the table");
table.setAddress(75);
Axis xAxis = new Axis("X Axis");
xAxis.setDescription("This is the X Axis");
xAxis.setAddress(0);
xAxis.setSize(5);
table.setXaxis(xAxis);
Axis yAxis = new Axis("Y Axis");
yAxis.setDescription("This is the Y Axis");
yAxis.setAddress(25);
yAxis.setSize(5);
table.setYaxis(yAxis);
//
// Create scales
//
Unit tableUnit = new Unit("Table Unit");
tableUnit.setCoarseIncrement(2);
tableUnit.setFineIncrement(1);
tableUnit.setFormat("0.0");
tableUnit.setTo_byte("x / 2");
tableUnit.setTo_real("x * 2");
Scale tableScale = new Scale("Table Scale");
Unit[] tableUnits = {tableUnit};
tableScale.setUnits(tableUnits);
tableScale.setDescription("This is the table scale");
tableScale.setEndian(Scale.ENDIAN_BIG);
tableScale.setStorageType(Scale.STORAGE_TYPE_UINT16);
table.setScale(tableScale);
Unit xUnit = new Unit("X Unit");
xUnit.setCoarseIncrement(2);
xUnit.setFineIncrement(1);
xUnit.setFormat("0.0");
xUnit.setTo_byte("x / 2");
xUnit.setTo_real("x * 2");
Scale xScale = new Scale("X Scale");
Unit[] xUnits = {xUnit};
xScale.setUnits(xUnits);
xScale.setDescription("This is the x scale");
xScale.setEndian(Scale.ENDIAN_LITTLE);
xScale.setStorageType(Scale.STORAGE_TYPE_INT8);
xAxis.setScale(xScale);
Unit yUnit = new Unit("Y Unit");
yUnit.setCoarseIncrement(3);
yUnit.setFineIncrement(2);
yUnit.setFormat("0.00");
yUnit.setTo_byte("x * 2");
yUnit.setTo_real("x / 2");
Scale yScale = new Scale("Y Scale");
Unit[] yUnits = {yUnit};
yScale.setUnits(yUnits);
yScale.setDescription("This is the y scale");
yScale.setEndian(Scale.ENDIAN_LITTLE);
yScale.setStorageType(Scale.STORAGE_TYPE_FLOAT);
yAxis.setScale(yScale);
//
// Create frame
//
Frame3D frame = new Frame3D(data, table);
frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
frame.pack(); frame.pack();
frame.setLocationRelativeTo( null ); frame.setLocationRelativeTo( null );
frame.setVisible(true);*/ frame.setVisible(true);
} }

View File

@ -0,0 +1,26 @@
/*
* ECUDataBuilder.java
*
* Created on January 22, 2007, 4:46 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package enginuity.newmaps.util;
import enginuity.newmaps.ecumetadata.TableMetadata;
import enginuity.newmaps.gui.EnginuityJTable;
/**
*
* @author Jared
*/
public class ECUDataBuilder {
public EnginuityJTable EnginuityTableBuilder(byte[] data, TableMetadata metadata) {
return null;
}
}

View File

@ -27,7 +27,7 @@ public final class ByteUtil {
private ByteUtil() { private ByteUtil() {
} }
public static int asInt(byte[] bytes) { public static int asUnsignedInt(byte[] bytes) {
int i = 0; int i = 0;
for (int j = 0; j < bytes.length; j++) { for (int j = 0; j < bytes.length; j++) {
if (j > 0) { if (j > 0) {
@ -46,7 +46,7 @@ public final class ByteUtil {
return Byte.valueOf(b).intValue(); return Byte.valueOf(b).intValue();
} }
public static byte[] asBytes(int i) { public static byte[] asUnsignedBytes(int i) {
byte[] b = new byte[4]; byte[] b = new byte[4];
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
int offset = (b.length - 1 - j) << 3; int offset = (b.length - 1 - j) << 3;
@ -56,7 +56,7 @@ public final class ByteUtil {
} }
public static float asFloat(byte[] bytes) { public static float asFloat(byte[] bytes) {
return Float.intBitsToFloat(asInt(bytes)); return Float.intBitsToFloat(asUnsignedInt(bytes));
} }
} }