Skip to content

Commit

Permalink
smarter auto-format
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Dec 31, 2023
1 parent b08dd8c commit b4b934d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/main/java/com/rusefi/can/reader/CANLineReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.rusefi.can.CANPacket;
import com.rusefi.can.reader.impl.CANoeReader;
import com.rusefi.can.reader.impl.CanHackerReader;
import com.rusefi.can.reader.impl.PcanTrcReader1_1;
import com.rusefi.can.reader.impl.*;

import java.io.IOException;
Expand Down Expand Up @@ -33,7 +32,7 @@ static CANLineReader getReader() {
return CanHackerReader.INSTANCE;
case PCAN:
default:
return PcanAutoReader.INSTANCE;
return AutoFormatReader.INSTANCE;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import java.nio.file.Paths;
import java.util.List;

public class PcanAutoReader implements CANLineReader {
public static final CANLineReader INSTANCE = new PcanAutoReader();
public class AutoFormatReader implements CANLineReader {
public static final CANLineReader INSTANCE = new AutoFormatReader();

private CANLineReader delegate;

Expand All @@ -26,9 +26,11 @@ public CANPacket readLine(String line, String fileName, int lineIndex) {
@Override
public List<CANPacket> readFile(String fileName) throws IOException {
String firstLine = Files.lines(Paths.get(fileName)).findFirst().get();
if (!firstLine.contains(PcanTrcReader2_0.FILEVERSION))
if (!firstLine.contains(PcanTrcReader2_0.FILEVERSION) && !firstLine.contains(CanHackerReader.HEADER))
throw new IllegalStateException(PcanTrcReader2_0.FILEVERSION + " expected in first line");
if (firstLine.contains("1.1")) {
if (firstLine.contains(CanHackerReader.HEADER)) {
delegate = CanHackerReader.INSTANCE;
} else if (firstLine.contains("1.1")) {
delegate = PcanTrcReader1_1.INSTANCE;
} else if (firstLine.contains("2.0")) {
delegate = PcanTrcReader2_0.INSTANCE;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/rusefi/can/reader/impl/CanHackerReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
public enum CanHackerReader implements CANLineReader {
INSTANCE;

public static final String HEADER = "@ TEXT";

@Override
public CANPacket readLine(String line, String fileName, int lineIndex) {
line = line.trim();
Expand Down

0 comments on commit b4b934d

Please sign in to comment.