From c9580eaaf558742f1fac2b492e7334275d3a1a4d Mon Sep 17 00:00:00 2001 From: rusefillc Date: Wed, 6 Nov 2024 18:38:20 -0500 Subject: [PATCH] applyOrderForStartOffset --- .../com/rusefi/can/reader/dbc/DbcField.java | 2 +- .../com/rusefi/can/reader/dbc/DbcFile.java | 1 + .../rusefi/can/reader/impl/ParseDBCTest.java | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/reader/src/main/java/com/rusefi/can/reader/dbc/DbcField.java b/reader/src/main/java/com/rusefi/can/reader/dbc/DbcField.java index b047180..1f882e1 100644 --- a/reader/src/main/java/com/rusefi/can/reader/dbc/DbcField.java +++ b/reader/src/main/java/com/rusefi/can/reader/dbc/DbcField.java @@ -14,7 +14,7 @@ public class DbcField { public DbcField(String name, int startOffset, int length, double mult, double offset, String category, boolean isBigEndian) { this.name = name; - this.startOffset = startOffset; + this.startOffset = isBigEndian && DbcFile.applyOrderForStartOffset ? startOffset - length + 1 : startOffset; this.length = length; this.mult = mult; this.offset = offset; diff --git a/reader/src/main/java/com/rusefi/can/reader/dbc/DbcFile.java b/reader/src/main/java/com/rusefi/can/reader/dbc/DbcFile.java index b07749d..bbae7e7 100644 --- a/reader/src/main/java/com/rusefi/can/reader/dbc/DbcFile.java +++ b/reader/src/main/java/com/rusefi/can/reader/dbc/DbcFile.java @@ -13,6 +13,7 @@ public class DbcFile { public final LinkedHashMap packets = new LinkedHashMap<>(); public static final boolean debugEnabled = false; + public static boolean applyOrderForStartOffset; private List list; diff --git a/reader/src/test/java/com/rusefi/can/reader/impl/ParseDBCTest.java b/reader/src/test/java/com/rusefi/can/reader/impl/ParseDBCTest.java index 9052165..87123ec 100644 --- a/reader/src/test/java/com/rusefi/can/reader/impl/ParseDBCTest.java +++ b/reader/src/test/java/com/rusefi/can/reader/impl/ParseDBCTest.java @@ -114,4 +114,24 @@ public void parse() throws IOException { assertEquals(0.25, rpm.getMult()); assertEquals("Motor_1", rpm.getCategory()); } + + @Test + public void parseMoto() throws IOException { + String moto = "BO_ 100 P: 8 ECM_HS\n" + + " SG_ OAT : 63|8@0+ (1,0) [0|8] \"deg C\" VICS"; + + BufferedReader reader = new BufferedReader(new StringReader(moto)); + + + DbcFile dbc = new DbcFile(false); + DbcFile.applyOrderForStartOffset = true; + dbc.read(reader); + + assertEquals(dbc.packets.size(), 1); + DbcPacket packet = dbc.packets.get(100); + assertNotNull(packet); + + DbcField f = packet.getFields().get(0); + assertEquals(56, f.getStartOffset()); + } }