From c147907aa4c12020abc316d9501387ff1832ed7a Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sat, 12 Nov 2022 22:13:12 -0500 Subject: [PATCH] already time for some clean-up --- src/main/java/com/rusefi/can/CAN2TS.java | 5 +++-- src/main/java/com/rusefi/can/CANPacket.java | 4 ++-- src/main/java/com/rusefi/can/SensorValue.java | 2 ++ .../com/rusefi/can/analysis/PerSidDump.java | 1 - .../can/{ => deprecated}/PacketPayload.java | 4 +++- .../can/{ => deprecated}/SensorType.java | 2 +- .../decoders/AbstractPacketDecoder.java | 8 +------- .../decoders/PacketDecoder.java | 4 ++-- .../{ => deprecated}/decoders/bmw/Bmw0A9.java | 8 ++++---- .../{ => deprecated}/decoders/bmw/Bmw0AA.java | 8 ++++---- .../{ => deprecated}/decoders/bmw/Bmw0B5.java | 8 ++++---- .../{ => deprecated}/decoders/bmw/Bmw0B6.java | 6 +++--- .../{ => deprecated}/decoders/bmw/Bmw0BA.java | 8 ++++---- .../{ => deprecated}/decoders/bmw/Bmw192.java | 8 ++++---- .../{ => deprecated}/decoders/bmw/Bmw1D0.java | 8 ++++---- .../decoders/bmw/BmwRegistry.java | 4 ++-- .../com/rusefi/can/reader/CANLineReader.java | 9 ++++----- src/main/java/com/rusefi/can/reader/README.md | 1 + .../can/{ => reader}/ReaderTypeHolder.java | 6 +++--- ...canTrcReader.java => PcanTrcReader1_1.java} | 10 +++++++++- .../{PcanReader.java => PcanTrcReader2_0.java} | 10 +++++++++- src/main/java/com/rusefi/util/BitMathUtil.java | 7 +++++++ .../java/com/rusefi/can/BmwE65DecoderTest.java | 10 ++++++---- .../rusefi/can/ByteRateOfChangeSandbox.java | 1 + .../BmwPcanCanValidatorSandbox.java} | 8 ++++---- .../can/deprecated}/CANoeCanValidator.java | 18 ++++++++++++------ .../can/reader/impl/CANoeReaderTest.java | 1 - .../can/reader/impl/GetValueFromTrc.java | 2 +- .../can/reader/impl/ParseDbcFieldTest.java | 2 +- .../rusefi/can/reader/impl/PcanReaderTest.java | 4 ++-- .../can/reader/impl/TrcToMlqSandbox.java | 2 +- 31 files changed, 104 insertions(+), 75 deletions(-) rename src/main/java/com/rusefi/can/{ => deprecated}/PacketPayload.java (84%) rename src/main/java/com/rusefi/can/{ => deprecated}/SensorType.java (84%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/AbstractPacketDecoder.java (81%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/PacketDecoder.java (58%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw0A9.java (73%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw0AA.java (75%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw0B5.java (78%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw0B6.java (65%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw0BA.java (84%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw192.java (91%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/Bmw1D0.java (74%) rename src/main/java/com/rusefi/can/{ => deprecated}/decoders/bmw/BmwRegistry.java (80%) create mode 100644 src/main/java/com/rusefi/can/reader/README.md rename src/main/java/com/rusefi/can/{ => reader}/ReaderTypeHolder.java (68%) rename src/main/java/com/rusefi/can/reader/impl/{PcanTrcReader.java => PcanTrcReader1_1.java} (61%) rename src/main/java/com/rusefi/can/reader/impl/{PcanReader.java => PcanTrcReader2_0.java} (62%) create mode 100644 src/main/java/com/rusefi/util/BitMathUtil.java rename src/{main/java/com/rusefi/can/PcanCanValidator.java => test/java/com/rusefi/can/deprecated/BmwPcanCanValidatorSandbox.java} (80%) rename src/{main/java/com/rusefi/can => test/java/com/rusefi/can/deprecated}/CANoeCanValidator.java (64%) diff --git a/src/main/java/com/rusefi/can/CAN2TS.java b/src/main/java/com/rusefi/can/CAN2TS.java index 27d72e1..4b5b3fd 100644 --- a/src/main/java/com/rusefi/can/CAN2TS.java +++ b/src/main/java/com/rusefi/can/CAN2TS.java @@ -1,7 +1,8 @@ package com.rusefi.can; -import com.rusefi.can.decoders.PacketDecoder; -import com.rusefi.can.decoders.bmw.BmwRegistry; +import com.rusefi.can.deprecated.decoders.PacketDecoder; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.decoders.bmw.BmwRegistry; import com.rusefi.can.reader.impl.CANoeReader; import java.io.FileWriter; diff --git a/src/main/java/com/rusefi/can/CANPacket.java b/src/main/java/com/rusefi/can/CANPacket.java index db45252..57ba8cd 100644 --- a/src/main/java/com/rusefi/can/CANPacket.java +++ b/src/main/java/com/rusefi/can/CANPacket.java @@ -1,6 +1,6 @@ package com.rusefi.can; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.util.BitMathUtil; import static com.rusefi.can.Utils.bytesToHexWithSpaces; @@ -29,7 +29,7 @@ public class CANPacket { if (shift + bitIndex > 8) { value = value + getUnsigned(byteIndex + 1) * 256; } - return value >> shift & AbstractPacketDecoder.mask(bitWidth); + return value >> shift & BitMathUtil.mask(bitWidth); } public double getTimeStamp() { diff --git a/src/main/java/com/rusefi/can/SensorValue.java b/src/main/java/com/rusefi/can/SensorValue.java index 7eef2c5..bda6453 100644 --- a/src/main/java/com/rusefi/can/SensorValue.java +++ b/src/main/java/com/rusefi/can/SensorValue.java @@ -1,5 +1,7 @@ package com.rusefi.can; +import com.rusefi.can.deprecated.SensorType; + public class SensorValue { private final SensorType type; private final double value; diff --git a/src/main/java/com/rusefi/can/analysis/PerSidDump.java b/src/main/java/com/rusefi/can/analysis/PerSidDump.java index 79c2277..4e0d069 100644 --- a/src/main/java/com/rusefi/can/analysis/PerSidDump.java +++ b/src/main/java/com/rusefi/can/analysis/PerSidDump.java @@ -3,7 +3,6 @@ package com.rusefi.can.analysis; import com.rusefi.can.CANPacket; import com.rusefi.can.writer.SteveWriter; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; diff --git a/src/main/java/com/rusefi/can/PacketPayload.java b/src/main/java/com/rusefi/can/deprecated/PacketPayload.java similarity index 84% rename from src/main/java/com/rusefi/can/PacketPayload.java rename to src/main/java/com/rusefi/can/deprecated/PacketPayload.java index 6611df5..005c92c 100644 --- a/src/main/java/com/rusefi/can/PacketPayload.java +++ b/src/main/java/com/rusefi/can/deprecated/PacketPayload.java @@ -1,4 +1,6 @@ -package com.rusefi.can; +package com.rusefi.can.deprecated; + +import com.rusefi.can.SensorValue; public class PacketPayload { diff --git a/src/main/java/com/rusefi/can/SensorType.java b/src/main/java/com/rusefi/can/deprecated/SensorType.java similarity index 84% rename from src/main/java/com/rusefi/can/SensorType.java rename to src/main/java/com/rusefi/can/deprecated/SensorType.java index 92b8733..415245a 100644 --- a/src/main/java/com/rusefi/can/SensorType.java +++ b/src/main/java/com/rusefi/can/deprecated/SensorType.java @@ -1,4 +1,4 @@ -package com.rusefi.can; +package com.rusefi.can.deprecated; public enum SensorType { RPM, diff --git a/src/main/java/com/rusefi/can/decoders/AbstractPacketDecoder.java b/src/main/java/com/rusefi/can/deprecated/decoders/AbstractPacketDecoder.java similarity index 81% rename from src/main/java/com/rusefi/can/decoders/AbstractPacketDecoder.java rename to src/main/java/com/rusefi/can/deprecated/decoders/AbstractPacketDecoder.java index f962872..bf4f7ed 100644 --- a/src/main/java/com/rusefi/can/decoders/AbstractPacketDecoder.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/AbstractPacketDecoder.java @@ -1,9 +1,7 @@ -package com.rusefi.can.decoders; +package com.rusefi.can.deprecated.decoders; import com.rusefi.can.CANPacket; -import java.util.Arrays; - import static com.rusefi.can.Utils.bytesToHexWithSpaces; public abstract class AbstractPacketDecoder implements PacketDecoder { @@ -13,10 +11,6 @@ public abstract class AbstractPacketDecoder implements PacketDecoder { this.id = id; } - public static int mask(int bitWidth) { - return (1 << bitWidth) - 1; - } - @Override public int getId() { return id; diff --git a/src/main/java/com/rusefi/can/decoders/PacketDecoder.java b/src/main/java/com/rusefi/can/deprecated/decoders/PacketDecoder.java similarity index 58% rename from src/main/java/com/rusefi/can/decoders/PacketDecoder.java rename to src/main/java/com/rusefi/can/deprecated/decoders/PacketDecoder.java index da54d95..72a0f43 100644 --- a/src/main/java/com/rusefi/can/decoders/PacketDecoder.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/PacketDecoder.java @@ -1,7 +1,7 @@ -package com.rusefi.can.decoders; +package com.rusefi.can.deprecated.decoders; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; +import com.rusefi.can.deprecated.PacketPayload; public interface PacketDecoder { PacketPayload decode(CANPacket packet); diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0A9.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0A9.java similarity index 73% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw0A9.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0A9.java index db743de..a21b4e7 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0A9.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0A9.java @@ -1,10 +1,10 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.SensorType; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; import com.rusefi.can.SensorValue; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; public class Bmw0A9 extends AbstractPacketDecoder { public static final AbstractPacketDecoder INSTANCE = new Bmw0A9(); diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0AA.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0AA.java similarity index 75% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw0AA.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0AA.java index 11664c3..ea0cb74 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0AA.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0AA.java @@ -1,10 +1,10 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.SensorType; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; import com.rusefi.can.SensorValue; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; public class Bmw0AA extends AbstractPacketDecoder { public static final int ID = 0xAA; diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0B5.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0B5.java similarity index 78% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw0B5.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0B5.java index 766233b..880f60f 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0B5.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0B5.java @@ -1,10 +1,10 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.SensorType; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; import com.rusefi.can.SensorValue; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; public class Bmw0B5 extends AbstractPacketDecoder { public static final AbstractPacketDecoder INSTANCE = new Bmw0B5(); diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0B6.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0B6.java similarity index 65% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw0B6.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0B6.java index 5250ffd..94d481a 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0B6.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0B6.java @@ -1,8 +1,8 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; public class Bmw0B6 extends AbstractPacketDecoder { public static final AbstractPacketDecoder INSTANCE = new Bmw0B6(); diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0BA.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0BA.java similarity index 84% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw0BA.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0BA.java index 74ef130..2aabd73 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw0BA.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw0BA.java @@ -1,10 +1,10 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.SensorType; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; import com.rusefi.can.SensorValue; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; public class Bmw0BA extends AbstractPacketDecoder { public static final int ID = 0x0BA; diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw192.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw192.java similarity index 91% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw192.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw192.java index dd02343..c1b09c6 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw192.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw192.java @@ -1,10 +1,10 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.SensorType; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; import com.rusefi.can.SensorValue; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; /** * Gear change request diff --git a/src/main/java/com/rusefi/can/decoders/bmw/Bmw1D0.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw1D0.java similarity index 74% rename from src/main/java/com/rusefi/can/decoders/bmw/Bmw1D0.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw1D0.java index ede3ecf..d2baf68 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/Bmw1D0.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/Bmw1D0.java @@ -1,10 +1,10 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; import com.rusefi.can.CANPacket; -import com.rusefi.can.PacketPayload; -import com.rusefi.can.SensorType; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; import com.rusefi.can.SensorValue; -import com.rusefi.can.decoders.AbstractPacketDecoder; +import com.rusefi.can.deprecated.decoders.AbstractPacketDecoder; public class Bmw1D0 extends AbstractPacketDecoder { public Bmw1D0() { diff --git a/src/main/java/com/rusefi/can/decoders/bmw/BmwRegistry.java b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/BmwRegistry.java similarity index 80% rename from src/main/java/com/rusefi/can/decoders/bmw/BmwRegistry.java rename to src/main/java/com/rusefi/can/deprecated/decoders/bmw/BmwRegistry.java index 6b92d76..473efa5 100644 --- a/src/main/java/com/rusefi/can/decoders/bmw/BmwRegistry.java +++ b/src/main/java/com/rusefi/can/deprecated/decoders/bmw/BmwRegistry.java @@ -1,6 +1,6 @@ -package com.rusefi.can.decoders.bmw; +package com.rusefi.can.deprecated.decoders.bmw; -import com.rusefi.can.decoders.PacketDecoder; +import com.rusefi.can.deprecated.decoders.PacketDecoder; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/com/rusefi/can/reader/CANLineReader.java b/src/main/java/com/rusefi/can/reader/CANLineReader.java index 527a979..afa4378 100644 --- a/src/main/java/com/rusefi/can/reader/CANLineReader.java +++ b/src/main/java/com/rusefi/can/reader/CANLineReader.java @@ -1,11 +1,9 @@ package com.rusefi.can.reader; import com.rusefi.can.CANPacket; -import com.rusefi.can.ReaderTypeHolder; -import com.rusefi.can.TrcToMlq; import com.rusefi.can.reader.impl.CANoeReader; import com.rusefi.can.reader.impl.CanHackerReader; -import com.rusefi.can.reader.impl.PcanTrcReader; +import com.rusefi.can.reader.impl.PcanTrcReader1_1; import java.io.IOException; import java.nio.file.Files; @@ -16,7 +14,8 @@ import java.util.function.Consumer; import java.util.stream.Stream; public interface CANLineReader { - char FLOAT_DIVIDER = new Double(0).toString().charAt(1); + // locale drama is here? todo: more flexibility? + char FLOAT_DIVIDER = Double.toString(0).charAt(1); static byte[] readHexArray(String[] tokens, int start, int size) { byte[] data = new byte[size]; @@ -33,7 +32,7 @@ public interface CANLineReader { return CanHackerReader.INSTANCE; case PCAN: default: - return new PcanTrcReader(); + return new PcanTrcReader1_1(); } } diff --git a/src/main/java/com/rusefi/can/reader/README.md b/src/main/java/com/rusefi/can/reader/README.md new file mode 100644 index 0000000..e8882a1 --- /dev/null +++ b/src/main/java/com/rusefi/can/reader/README.md @@ -0,0 +1 @@ +Reading logic for multiple formats of CAN trace logs \ No newline at end of file diff --git a/src/main/java/com/rusefi/can/ReaderTypeHolder.java b/src/main/java/com/rusefi/can/reader/ReaderTypeHolder.java similarity index 68% rename from src/main/java/com/rusefi/can/ReaderTypeHolder.java rename to src/main/java/com/rusefi/can/reader/ReaderTypeHolder.java index 4dd9476..7c33e73 100644 --- a/src/main/java/com/rusefi/can/ReaderTypeHolder.java +++ b/src/main/java/com/rusefi/can/reader/ReaderTypeHolder.java @@ -1,11 +1,11 @@ -package com.rusefi.can; +package com.rusefi.can.reader; -import com.rusefi.can.reader.ReaderType; +import com.rusefi.can.TrcToMlq; public enum ReaderTypeHolder { INSTANCE; - ReaderType type; + public ReaderType type; public ReaderType getType() { if (type == null) diff --git a/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader.java b/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader1_1.java similarity index 61% rename from src/main/java/com/rusefi/can/reader/impl/PcanTrcReader.java rename to src/main/java/com/rusefi/can/reader/impl/PcanTrcReader1_1.java index be55037..9742b83 100644 --- a/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader.java +++ b/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader1_1.java @@ -3,10 +3,18 @@ package com.rusefi.can.reader.impl; import com.rusefi.can.CANPacket; import com.rusefi.can.reader.CANLineReader; -public class PcanTrcReader implements CANLineReader { +import static com.rusefi.can.reader.impl.PcanTrcReader2_0.FILEVERSION; + +/** + * @see PcanTrcReader2_0 for version 2.0 format + * TODO: merge these two? + */ +public class PcanTrcReader1_1 implements CANLineReader { @Override public CANPacket readLine(String line) { line = line.trim(); + if (line.startsWith(FILEVERSION) && !line.startsWith(FILEVERSION + "=1.1")) + throw new IllegalStateException("Unexpected fileversion " + line); if (line.startsWith(";")) return null; String[] tokens = line.split("\\s+"); diff --git a/src/main/java/com/rusefi/can/reader/impl/PcanReader.java b/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader2_0.java similarity index 62% rename from src/main/java/com/rusefi/can/reader/impl/PcanReader.java rename to src/main/java/com/rusefi/can/reader/impl/PcanTrcReader2_0.java index 0cb58bc..da440cf 100644 --- a/src/main/java/com/rusefi/can/reader/impl/PcanReader.java +++ b/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader2_0.java @@ -3,12 +3,20 @@ package com.rusefi.can.reader.impl; import com.rusefi.can.CANPacket; import com.rusefi.can.reader.CANLineReader; -public enum PcanReader implements CANLineReader { +/** + * @see PcanTrcReader1_1 for version 1.1 format + * TODO: merge these two? + */ +public enum PcanTrcReader2_0 implements CANLineReader { INSTANCE; + public static final String FILEVERSION = ";$FILEVERSION"; + @Override public CANPacket readLine(String line) { line = line.trim(); + if (line.startsWith(FILEVERSION) && !line.startsWith(FILEVERSION + "=2.0")) + throw new IllegalStateException("Unexpected fileversion " + line); if (line.startsWith(";")) return null; String[] tokens = line.split("\\s+"); diff --git a/src/main/java/com/rusefi/util/BitMathUtil.java b/src/main/java/com/rusefi/util/BitMathUtil.java new file mode 100644 index 0000000..a5f0a27 --- /dev/null +++ b/src/main/java/com/rusefi/util/BitMathUtil.java @@ -0,0 +1,7 @@ +package com.rusefi.util; + +public class BitMathUtil { + public static int mask(int bitWidth) { + return (1 << bitWidth) - 1; + } +} diff --git a/src/test/java/com/rusefi/can/BmwE65DecoderTest.java b/src/test/java/com/rusefi/can/BmwE65DecoderTest.java index 7685211..232d432 100644 --- a/src/test/java/com/rusefi/can/BmwE65DecoderTest.java +++ b/src/test/java/com/rusefi/can/BmwE65DecoderTest.java @@ -1,9 +1,11 @@ package com.rusefi.can; -import com.rusefi.can.decoders.bmw.Bmw0A9; -import com.rusefi.can.decoders.bmw.Bmw0AA; -import com.rusefi.can.decoders.bmw.Bmw0B5; -import com.rusefi.can.decoders.bmw.Bmw1D0; +import com.rusefi.can.deprecated.PacketPayload; +import com.rusefi.can.deprecated.SensorType; +import com.rusefi.can.deprecated.decoders.bmw.Bmw0A9; +import com.rusefi.can.deprecated.decoders.bmw.Bmw0AA; +import com.rusefi.can.deprecated.decoders.bmw.Bmw0B5; +import com.rusefi.can.deprecated.decoders.bmw.Bmw1D0; import org.junit.Test; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java b/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java index 8229bba..8d2cb14 100644 --- a/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java +++ b/src/test/java/com/rusefi/can/ByteRateOfChangeSandbox.java @@ -4,6 +4,7 @@ import com.rusefi.can.analysis.ByteRateOfChange; import com.rusefi.can.analysis.ByteRateOfChangeReports; import com.rusefi.can.reader.CANLineReader; import com.rusefi.can.reader.ReaderType; +import com.rusefi.can.reader.ReaderTypeHolder; import com.rusefi.util.FolderUtil; import java.io.File; diff --git a/src/main/java/com/rusefi/can/PcanCanValidator.java b/src/test/java/com/rusefi/can/deprecated/BmwPcanCanValidatorSandbox.java similarity index 80% rename from src/main/java/com/rusefi/can/PcanCanValidator.java rename to src/test/java/com/rusefi/can/deprecated/BmwPcanCanValidatorSandbox.java index 6916eb3..82b284d 100644 --- a/src/main/java/com/rusefi/can/PcanCanValidator.java +++ b/src/test/java/com/rusefi/can/deprecated/BmwPcanCanValidatorSandbox.java @@ -1,13 +1,13 @@ -package com.rusefi.can; +package com.rusefi.can.deprecated; import com.rusefi.can.reader.CANLineReader; -import com.rusefi.can.reader.impl.PcanReader; +import com.rusefi.can.reader.impl.PcanTrcReader2_0; import java.io.IOException; -public class PcanCanValidator { +public class BmwPcanCanValidatorSandbox { public static void main(String[] args) throws IOException { - CANLineReader reader = PcanReader.INSTANCE; + CANLineReader reader = PcanTrcReader2_0.INSTANCE; // CANoeCanValidator.validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\E65-760-andrey-2021-feb-21-engine-off-acc-on.trc", reader); // CANoeCanValidator.validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\E65-760-andrey-2021-feb-21-engine-off-inpa-tcu-reset-codes.trc", reader); diff --git a/src/main/java/com/rusefi/can/CANoeCanValidator.java b/src/test/java/com/rusefi/can/deprecated/CANoeCanValidator.java similarity index 64% rename from src/main/java/com/rusefi/can/CANoeCanValidator.java rename to src/test/java/com/rusefi/can/deprecated/CANoeCanValidator.java index 8d93439..251e58a 100644 --- a/src/main/java/com/rusefi/can/CANoeCanValidator.java +++ b/src/test/java/com/rusefi/can/deprecated/CANoeCanValidator.java @@ -1,7 +1,8 @@ -package com.rusefi.can; +package com.rusefi.can.deprecated; -import com.rusefi.can.decoders.bmw.Bmw0BA; -import com.rusefi.can.decoders.bmw.Bmw192; +import com.rusefi.can.CANPacket; +import com.rusefi.can.deprecated.decoders.bmw.Bmw0BA; +import com.rusefi.can.deprecated.decoders.bmw.Bmw192; import com.rusefi.can.reader.CANLineReader; import com.rusefi.can.reader.impl.CANoeReader; @@ -10,6 +11,9 @@ import java.io.IOException; import java.util.List; import java.util.TreeMap; +/** + * this code looks to validate BMW logs against hard-coded BMW packet logic? dead stuff since we've moved to DBC approach? + */ public class CANoeCanValidator { public static void main(String[] args) throws IOException { CANLineReader reader = CANoeReader.INSTANCE; @@ -18,8 +22,8 @@ public class CANoeCanValidator { } - public static void validate(String fileName, CANLineReader reader) throws IOException { - List packetList = reader.readFile(fileName); + public static void validate(String inputFileName, CANLineReader reader) throws IOException { + List packetList = reader.readFile(inputFileName); TreeMap allIds = new TreeMap<>(); @@ -34,7 +38,9 @@ public class CANoeCanValidator { } - try (FileWriter fw = new FileWriter("all_ids.txt")) { + String outputFileName = "all_ids.txt"; + System.out.println("Writing to " + outputFileName); + try (FileWriter fw = new FileWriter(outputFileName)) { for (Integer id : allIds.keySet()) { fw.write(Integer.toHexString(id) + "\r\n"); } diff --git a/src/test/java/com/rusefi/can/reader/impl/CANoeReaderTest.java b/src/test/java/com/rusefi/can/reader/impl/CANoeReaderTest.java index a0f8ac0..661bba7 100644 --- a/src/test/java/com/rusefi/can/reader/impl/CANoeReaderTest.java +++ b/src/test/java/com/rusefi/can/reader/impl/CANoeReaderTest.java @@ -2,7 +2,6 @@ package com.rusefi.can.reader.impl; import com.rusefi.can.CANPacket; -import com.rusefi.can.reader.impl.CANoeReader; import org.junit.Test; import static junit.framework.TestCase.assertEquals; diff --git a/src/test/java/com/rusefi/can/reader/impl/GetValueFromTrc.java b/src/test/java/com/rusefi/can/reader/impl/GetValueFromTrc.java index c02a65c..02b1f27 100644 --- a/src/test/java/com/rusefi/can/reader/impl/GetValueFromTrc.java +++ b/src/test/java/com/rusefi/can/reader/impl/GetValueFromTrc.java @@ -31,7 +31,7 @@ public class GetValueFromTrc { String trcLine = " 3769) 2117.7 Rx 0280 8 01 1D DF 12 1E 00 1A 1E "; - PcanTrcReader reader = new PcanTrcReader(); + PcanTrcReader1_1 reader = new PcanTrcReader1_1(); CANPacket packet = reader.readLine(trcLine); assertEquals(8, packet.getData().length); assertEquals(640, packet.getId()); diff --git a/src/test/java/com/rusefi/can/reader/impl/ParseDbcFieldTest.java b/src/test/java/com/rusefi/can/reader/impl/ParseDbcFieldTest.java index faa9c90..3e77e1e 100644 --- a/src/test/java/com/rusefi/can/reader/impl/ParseDbcFieldTest.java +++ b/src/test/java/com/rusefi/can/reader/impl/ParseDbcFieldTest.java @@ -20,7 +20,7 @@ public class ParseDbcFieldTest { assertEquals(0.75, iatField.getMult(), EPS); assertEquals(-48, iatField.getOffset(), EPS); - CANPacket packet = new PcanTrcReader().readLine(" 2197) 1234.8 Rx 0380 8 00 62 FA 00 22 00 00 FA"); + CANPacket packet = new PcanTrcReader1_1().readLine(" 2197) 1234.8 Rx 0380 8 00 62 FA 00 22 00 00 FA"); assertEquals(8, packet.getData().length); assertEquals(25.5, iatField.getValue(packet), EPS); diff --git a/src/test/java/com/rusefi/can/reader/impl/PcanReaderTest.java b/src/test/java/com/rusefi/can/reader/impl/PcanReaderTest.java index d2223ef..4a5b920 100644 --- a/src/test/java/com/rusefi/can/reader/impl/PcanReaderTest.java +++ b/src/test/java/com/rusefi/can/reader/impl/PcanReaderTest.java @@ -1,7 +1,7 @@ package com.rusefi.can.reader.impl; import com.rusefi.can.CANPacket; -import com.rusefi.can.decoders.bmw.Bmw192; +import com.rusefi.can.deprecated.decoders.bmw.Bmw192; import com.rusefi.can.reader.CANLineReader; import org.junit.Test; @@ -10,7 +10,7 @@ import static junit.framework.TestCase.assertEquals; public class PcanReaderTest { @Test public void testLine() { - CANLineReader reader = PcanReader.INSTANCE; + CANLineReader reader = PcanTrcReader2_0.INSTANCE; CANPacket packet = reader.readLine(" 15883 77333097.212 DT 0192 Rx 4 2D 04 80 F9 "); assertEquals(4, packet.getData().length); assertEquals(Bmw192.ID, packet.getId()); diff --git a/src/test/java/com/rusefi/can/reader/impl/TrcToMlqSandbox.java b/src/test/java/com/rusefi/can/reader/impl/TrcToMlqSandbox.java index 1e21848..d1a94f6 100644 --- a/src/test/java/com/rusefi/can/reader/impl/TrcToMlqSandbox.java +++ b/src/test/java/com/rusefi/can/reader/impl/TrcToMlqSandbox.java @@ -23,7 +23,7 @@ public class TrcToMlqSandbox { dbc.read(reader); } - List packets = new PcanTrcReader().readFile(trcFileName); + List packets = new PcanTrcReader1_1().readFile(trcFileName); System.out.println(packets.size() + " packets"); LoggingStrategy.writeLog(dbc, packets, "gauges.mlg");