diff --git a/src/enginuity/newmaps/ecudata/AxisData.java b/src/enginuity/newmaps/ecudata/AxisData.java index 61190dc1..d08292cd 100644 --- a/src/enginuity/newmaps/ecudata/AxisData.java +++ b/src/enginuity/newmaps/ecudata/AxisData.java @@ -26,23 +26,27 @@ import enginuity.newmaps.ecumetadata.Scale; import enginuity.newmaps.util.ECUDataUtil; public class AxisData extends TableData { - + public AxisData(byte[] data, AxisMetadata metadata) { this.metadata = metadata; populate(data); } - + public boolean populate(byte[] data) { - Scale scale = metadata.getScale(); + Scale scale = metadata.getScale(); /*float values[] = ECUDataUtil.calcRealValues(data, scale.getStorageType(), - metadata.getAddress(), metadata.getSize(), + metadata.getAddress(), metadata.getSize(), scale.getEndian(), scale.getUnit().getTo_real());*/ return true; } - + + public int getSize() { + return metadata.getSize(); + } + public byte[] returnValues() { - + return null; } - + } diff --git a/src/enginuity/newmaps/ecudata/Table3DData.java b/src/enginuity/newmaps/ecudata/Table3DData.java index eafaf26d..9a35537e 100644 --- a/src/enginuity/newmaps/ecudata/Table3DData.java +++ b/src/enginuity/newmaps/ecudata/Table3DData.java @@ -23,43 +23,44 @@ package enginuity.newmaps.ecudata; import enginuity.newmaps.ecumetadata.Table3DMetadata; import enginuity.newmaps.exception.DataPopulationException; +import enginuity.newmaps.util.ECUDataUtil; import enginuity.util.ByteUtil; public class Table3DData extends TableData { - + private DataCell[][] values; private AxisData xAxis; private AxisData yAxis; - + public Table3DData(byte[] data, Table3DMetadata metadata) throws DataPopulationException { this.metadata = metadata; populate(data); } - + public DataCell[][] getValues() { return values; } - + public DataCell getValueAt(int x, int y) throws IndexOutOfBoundsException { return values[x][y]; } - + public byte[] returnValues() { // Returns updated byte values to ECUData - + // TODO: Find return values (using ECUDataUtil) return null; } - + public boolean populate(byte[] data) { - + // populate axes first xAxis.populate(data); yAxis.populate(data); - + // Now populate the table itself - int dataSize = ByteUtil.getLengthInBytes(metadata.getScale().getStorageType()); + DataCell[] rawData = ECUDataUtil.buildValues(data, metadata); return true; } - + } diff --git a/src/enginuity/newmaps/util/ECUDataUtil.java b/src/enginuity/newmaps/util/ECUDataUtil.java index 566c4a32..326ccff9 100644 --- a/src/enginuity/newmaps/util/ECUDataUtil.java +++ b/src/enginuity/newmaps/util/ECUDataUtil.java @@ -21,6 +21,7 @@ package enginuity.newmaps.util; +import enginuity.newmaps.ecudata.DataCell; import enginuity.newmaps.ecudata.TableData; import enginuity.newmaps.ecumetadata.Scale; import enginuity.newmaps.ecumetadata.Table3DMetadata; @@ -29,21 +30,65 @@ import enginuity.util.ByteUtil; import enginuity.util.JEPUtil; public final class ECUDataUtil { - - public static TableData getTableData(byte[] data, TableMetadata metadata) { - - if (metadata instanceof Table3DMetadata) { - - } - - return null; - } - - + public static byte[] getTableAsBytes() { // TODO: build byte arrays from table data return null; } - - + + + // + // Populate 1d and 2d tables + // + public static DataCell[] buildValues(byte[] input, TableMetadata metadata) { + + DataCell[] output = new DataCell[metadata.getSize()]; + int dataSize = ByteUtil.getLengthInBytes(metadata.getScale().getStorageType()); + int storageType = metadata.getScale().getStorageType(); + int endian = metadata.getScale().getEndian(); + int address = metadata.getAddress(); + + for (int j = 0; j < metadata.getSize(); j++) { + + // Build single datacell bytes + byte[] cellBytes = new byte[dataSize]; + for (int i = 0; i < dataSize; i++) { + cellBytes[i] = input[address + dataSize * j]; + } + + // Get DataCell and add to array + output[j] = new DataCell(cellBytes, storageType, endian); + } + return output; + } + + + // + // Populate 3d tables + // + public static DataCell[][] buildValues(byte[] input, Table3DMetadata metadata) { + + DataCell[][] output = new DataCell[metadata.getSizeX()][metadata.getSizeY()]; + int dataSize = ByteUtil.getLengthInBytes(metadata.getScale().getStorageType()); + int storageType = metadata.getScale().getStorageType(); + int endian = metadata.getScale().getEndian(); + int address = metadata.getAddress(); + + for (int x = 0; x < metadata.getSizeX(); x++) { + for (int y = 0; y < metadata.getSizeY(); y++) { + + // Build single datacell bytes + byte[] cellBytes = new byte[dataSize]; + for (int i = 0; i < dataSize; i++) { + cellBytes[i] = input[address + dataSize * x * y]; + } + + // Get DataCell and add to array + output[x][y] = new DataCell(cellBytes, storageType, endian); + } + } + return output; + } + + }