Getting closer to a new test table window

git-svn-id: http://svn.3splooges.com/romraider-arch/trunk@491 d2e2e1cd-ba16-0410-be16-b7c4453c7c2d
This commit is contained in:
Jared Gould 2007-01-29 21:39:30 +00:00
parent 16f2d745b7
commit a3661e463b
4 changed files with 115 additions and 6 deletions

View File

@ -1,16 +1,47 @@
/*
*
* Enginuity Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006 Enginuity.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
package enginuity.newmaps.ecudata;
import enginuity.newmaps.ecumetadata.AxisMetadata;
import enginuity.newmaps.ecumetadata.Scale;
import enginuity.newmaps.util.ECUDataUtil;
public class AxisData extends TableData {
public AxisData() {
public AxisData(byte[] data, AxisMetadata metadata) {
this.metadata = metadata;
populate(data);
}
public boolean populate(byte[] data) {
Scale scale = metadata.getScale();
/*float values[] = ECUDataUtil.calcRealValues(data, scale.getStorageType(),
metadata.getAddress(), metadata.getSize(),
scale.getEndian(), scale.getUnit().getTo_real());*/
return true;
}
public byte[] returnValues() {
// TODO: Find return values (using ECUDataUtil)
return null;
}

View File

@ -0,0 +1,33 @@
/*
*
* Enginuity Open-Source Tuning, Logging and Reflashing
* Copyright (C) 2006 Enginuity.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
package enginuity.newmaps.ecudata;
public class DataCell {
byte[] bytes;
String displayValue;
public DataCell(byte[] bytes, int storageType) {
this.bytes = bytes;
}
}

View File

@ -22,9 +22,11 @@
package enginuity.newmaps.util;
import enginuity.newmaps.ecudata.TableData;
import enginuity.newmaps.ecumetadata.Scale;
import enginuity.newmaps.ecumetadata.Table3DMetadata;
import enginuity.newmaps.ecumetadata.TableMetadata;
import enginuity.newmaps.ecumetadata.Scale;
import enginuity.util.ByteUtil;
import enginuity.util.JEPUtil;
public final class ECUDataUtil {
@ -38,6 +40,42 @@ public final class ECUDataUtil {
}
public static float binaryToReal(byte[] data, int dataType, int endian, String to_real) {
float output = 0;
// Check endian
if (endian == Scale.ENDIAN_LITTLE) data = ByteUtil.reverseEndian(data);
// Calculate ECU values
if (dataType == Scale.STORAGE_TYPE_FLOAT) output = ByteUtil.asFloat(data);
else if (dataType == Scale.STORAGE_TYPE_INT8) output = ByteUtil.asSignedInt(data);
else if (dataType == Scale.STORAGE_TYPE_INT16) output = ByteUtil.asSignedInt(data);
else if (dataType == Scale.STORAGE_TYPE_INT32) output = ByteUtil.asSignedInt(data);
else if (dataType == Scale.STORAGE_TYPE_UINT8) output = ByteUtil.asUnsignedInt(data);
else if (dataType == Scale.STORAGE_TYPE_UINT16) output = ByteUtil.asUnsignedInt(data);
else if (dataType == Scale.STORAGE_TYPE_UINT32) output = ByteUtil.asUnsignedInt(data);
return (float)JEPUtil.evaluate(to_real, (double)output);
}
public static byte[] realToBinary(float realValue, int dataType, int endian, String to_byte) {
realValue = (float)JEPUtil.evaluate(to_byte, (double)realValue);
if (dataType == Scale.STORAGE_TYPE_FLOAT) return ByteUtil.asBytes(realValue);
else if (dataType == Scale.STORAGE_TYPE_INT8) return ByteUtil.asSignedBytes((int)realValue);
else if (dataType == Scale.STORAGE_TYPE_INT16) return ByteUtil.asSignedBytes((int)realValue);
else if (dataType == Scale.STORAGE_TYPE_INT32) return ByteUtil.asSignedBytes((int)realValue);
else if (dataType == Scale.STORAGE_TYPE_UINT8) return ByteUtil.asUnsignedBytes((int)realValue);
else if (dataType == Scale.STORAGE_TYPE_UINT16) return ByteUtil.asUnsignedBytes((int)realValue);
else if (dataType == Scale.STORAGE_TYPE_UINT32) return ByteUtil.asUnsignedBytes((int)realValue);
return null;
}
public static byte[] getTableAsBytes() {
// TODO: build byte arrays from table data
return null;

View File

@ -22,7 +22,8 @@
package enginuity.util;
import enginuity.newmaps.ecumetadata.Scale;
import enginuity.newmaps.ecumetadata.TableMetadata;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
@SuppressWarnings({"UnnecessaryBoxing"})
public final class ByteUtil {
@ -52,8 +53,7 @@ public final class ByteUtil {
return i;
}
private int getCellLengthInBytes(TableMetadata metadata) {
int type = metadata.getScale().getStorageType();
public static int getLengthInBytes(int type) {
if (type == Scale.STORAGE_TYPE_CHAR) return 1;
else if (type == Scale.STORAGE_TYPE_FLOAT) return 4;
@ -105,5 +105,12 @@ public final class ByteUtil {
public static float asFloat(byte[] bytes) {
return Float.intBitsToFloat(asUnsignedInt(bytes));
}
public static byte[] asBytes(float f) {
byte[] output = new byte[4];
ByteBuffer bb = ByteBuffer.wrap(output, 0, 4);
bb.putFloat(f);
return bb.array();
}
}