can-log-tools/reader/src/main/java/com/rusefi/can/reader/impl/PcanTrcReader1_1.java

34 lines
1.2 KiB
Java
Raw Normal View History

2022-06-20 18:29:27 -07:00
package com.rusefi.can.reader.impl;
import com.rusefi.can.CANPacket;
import com.rusefi.can.reader.CANLineReader;
2022-11-12 19:13:12 -08:00
/**
* @see PcanTrcReader2_0 for version 2.0 format
* TODO: merge these two?
*/
public class PcanTrcReader1_1 implements CANLineReader {
2023-10-14 09:17:23 -07:00
public static final CANLineReader INSTANCE = new PcanTrcReader1_1();
2022-06-20 18:29:27 -07:00
@Override
2023-12-15 07:38:17 -08:00
public CANPacket readLine(String line, String fileName, int lineIndex) {
2022-06-20 18:29:27 -07:00
line = line.trim();
2024-01-12 22:08:24 -08:00
if (line.startsWith(PcanTrcReader2_0.FILEVERSION) && !line.startsWith(PcanTrcReader2_0.FILEVERSION + "=1.1"))
2022-11-12 19:13:12 -08:00
throw new IllegalStateException("Unexpected fileversion " + line);
2022-06-20 18:29:27 -07:00
if (line.startsWith(";"))
return null;
String[] tokens = line.split("\\s+");
2023-12-15 07:38:17 -08:00
if (tokens.length < 2)
2023-12-15 07:43:39 -08:00
throw new IllegalStateException("Unexpected token count in " + fileName + "@" + lineIndex + ": [" + line + "]");
2022-06-20 18:29:27 -07:00
double timeStamp = Double.parseDouble(tokens[1]);
int sid = Integer.parseInt(tokens[3], 16);
int size = Integer.parseInt(tokens[4]);
byte[] data = CANLineReader.readHexArray(tokens, 5, size);
return new CANPacket(timeStamp, sid, data);
}
}