auto-detect pcan log version

This commit is contained in:
rusefillc 2023-10-14 12:17:23 -04:00
parent b871f745a6
commit 7d2b02b0d2
10 changed files with 78 additions and 15 deletions

View File

@ -11,7 +11,7 @@ import static com.rusefi.can.reader.CANLineReader.getReader;
public class TrcToMlq {
public static ReaderType parseCurrentReaderTypeSetting() {
String property = System.getProperty("TRACE_READER", ReaderType.PCAN2.name());
String property = System.getProperty("TRACE_READER", ReaderType.PCAN.name());
ReaderType readerType = ReaderType.valueOf(property);
System.out.println("getCurrentReaderType: " + readerType + " for [" + property + "]");
return readerType;

View File

@ -4,7 +4,7 @@ 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.PcanTrcReader2_0;
import com.rusefi.can.reader.impl.*;
import java.io.IOException;
import java.nio.file.Files;
@ -31,11 +31,9 @@ public interface CANLineReader {
return CANoeReader.INSTANCE;
case CANHACKER:
return CanHackerReader.INSTANCE;
case PCAN2:
return PcanTrcReader2_0.INSTANCE;
case PCAN1_1:
case PCAN:
default:
return new PcanTrcReader1_1();
return PcanAutoReader.INSTANCE;
}
}

View File

@ -1,9 +1,7 @@
package com.rusefi.can.reader;
public enum ReaderType {
PCAN1_1,
PCAN2,
PCAN,
CANOE,
CANHACKER,
}

View File

@ -0,0 +1,45 @@
package com.rusefi.can.reader.impl;
import com.rusefi.can.CANPacket;
import com.rusefi.can.reader.CANLineReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
public class PcanAutoReader implements CANLineReader {
public static final CANLineReader INSTANCE = new PcanAutoReader();
private CANLineReader delegate;
@Override
public CANPacket readLine(String line) {
return delegate.readLine(line);
}
@Override
public CANPacket readLine(String line, String fileName) {
return delegate.readLine(line, fileName);
}
@Override
public List<CANPacket> readFile(String fileName) throws IOException {
String firstLine = Files.lines(Paths.get(fileName)).findFirst().get();
if (!firstLine.contains(PcanTrcReader2_0.FILEVERSION))
throw new IllegalStateException(PcanTrcReader2_0.FILEVERSION + " expected in first line");
if (firstLine.contains("1.1")) {
delegate = PcanTrcReader1_1.INSTANCE;
} else if (firstLine.contains("2.0")) {
delegate = PcanTrcReader2_0.INSTANCE;
} else {
throw new IllegalStateException("Unsupported version in " + firstLine);
}
return delegate.readFile(fileName);
}
@Override
public List<CANPacket> skipHeaderAndRead(String fileName, int skipCount) throws IOException {
return delegate.skipHeaderAndRead(fileName, skipCount);
}
}

View File

@ -10,6 +10,8 @@ import static com.rusefi.can.reader.impl.PcanTrcReader2_0.FILEVERSION;
* TODO: merge these two?
*/
public class PcanTrcReader1_1 implements CANLineReader {
public static final CANLineReader INSTANCE = new PcanTrcReader1_1();
@Override
public CANPacket readLine(String line, String fileName) {
line = line.trim();

View File

@ -8,7 +8,7 @@ import java.io.IOException;
public class ByteRateOfChangeNissanSandbox {
public static void main(String[] args) throws IOException {
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN1_1;
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
String inputFolderName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\Nissan\\2011_Xterra\\CAN-Nov-2022";

View File

@ -8,7 +8,7 @@ import java.io.IOException;
public class ByteRateOfChangeVagSandbox {
public static void main(String[] args) throws IOException {
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN1_1;
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
String inputFolderName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\VAG\\2006-Passat-B6";

View File

@ -7,11 +7,10 @@ import com.rusefi.can.reader.ReaderTypeHolder;
import com.rusefi.can.reader.impl.PcanTrcReader2_0;
import java.io.IOException;
import java.util.List;
public class CanAmMG1Sandbox {
public static void main(String[] args) throws IOException {
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN1_1;
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
CANLineReader reader = PcanTrcReader2_0.INSTANCE;

View File

@ -8,7 +8,7 @@ import java.io.IOException;
public class KiaSandbox {
public static void main(String[] args) throws IOException {
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN2;
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
String inputFolderName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\Kia\\2013-CAN-logs";

View File

@ -1,6 +1,10 @@
package com.rusefi.can;
import com.rusefi.can.analysis.ByteRateOfChangeReports;
import com.rusefi.can.analysis.PerSidDump;
import com.rusefi.can.reader.CANLineReader;
import com.rusefi.can.reader.ReaderType;
import com.rusefi.can.reader.ReaderTypeHolder;
import com.rusefi.can.reader.dbc.DbcFile;
import com.rusefi.can.reader.impl.PcanTrcReader1_1;
import com.rusefi.can.reader.impl.ReadFullVagDbc;
@ -9,15 +13,32 @@ import com.rusefi.mlv.LoggingStrategy;
import java.io.IOException;
import java.util.List;
import static com.rusefi.can.analysis.ByteRateOfChangeReports.createOutputFolder;
public class VagB6Sandbox {
public static void main(String[] args) throws IOException {
DbcFile dbc = DbcFile.readFromFile(ReadFullVagDbc.VAG_DBC_FILE);
CANLineReader reader = new PcanTrcReader1_1();
String file = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\VAG\\2006-Passat-B6\\passat-back-and-forth-60-seconds.trc1";
String inputFolderName = "C:\\stuff\\rusefi_documentation\\OEM-Docs\\VAG\\2006-Passat-B6\\";
{
ReaderTypeHolder.INSTANCE.type = ReaderType.PCAN;
ByteRateOfChangeReports.scanInputFolder(inputFolderName + "2023.10-tcu-side2", ".trc");
}
String simpleFileName = "passat-back-and-forth-60-seconds.trc1";
String file = inputFolderName + simpleFileName;
String reportDestinationFolder = createOutputFolder(inputFolderName);
List<CANPacket> packets = reader.readFile(file);
PerSidDump.handle(reportDestinationFolder, simpleFileName, packets);
String outputFileName = "vag.mlg";
LoggingStrategy.writeLog(dbc, packets, outputFileName);
}