BusMasterReader
This commit is contained in:
parent
4067f21a05
commit
516a2b740c
|
@ -26,10 +26,15 @@ public class AutoFormatReader implements CANLineReader {
|
|||
@Override
|
||||
public List<CANPacket> readFile(String fileName) throws IOException {
|
||||
String firstLine = Files.lines(Paths.get(fileName)).findFirst().get();
|
||||
if (!firstLine.contains(PcanTrcReader2_0.FILEVERSION) && !firstLine.contains(CanHackerReader.HEADER))
|
||||
if (!firstLine.contains(PcanTrcReader2_0.FILEVERSION)
|
||||
&& !firstLine.contains(CanHackerReader.HEADER)
|
||||
&& !firstLine.contains(BusMasterReader.HEADER)
|
||||
)
|
||||
throw new IllegalStateException(PcanTrcReader2_0.FILEVERSION + " expected in first line");
|
||||
if (firstLine.contains(CanHackerReader.HEADER)) {
|
||||
delegate = CanHackerReader.INSTANCE;
|
||||
} else if (firstLine.contains(BusMasterReader.HEADER)) {
|
||||
delegate = BusMasterReader.INSTANCE;
|
||||
} else if (firstLine.contains("1.1")) {
|
||||
delegate = PcanTrcReader1_1.INSTANCE;
|
||||
} else if (firstLine.contains("2.0")) {
|
||||
|
@ -37,7 +42,11 @@ public class AutoFormatReader implements CANLineReader {
|
|||
} else {
|
||||
throw new IllegalStateException("Unsupported version in " + firstLine);
|
||||
}
|
||||
return delegate.readFile(fileName);
|
||||
try {
|
||||
return delegate.readFile(fileName);
|
||||
} catch (Throwable e) {
|
||||
throw new IllegalStateException("While " + fileName, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
package com.rusefi.can.reader.impl;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import com.rusefi.can.reader.CANLineReader;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
|
||||
public enum BusMasterReader implements CANLineReader {
|
||||
INSTANCE;
|
||||
|
||||
public static final CharSequence HEADER = "BUSMASTER Ver 3";
|
||||
final String FORMAT = "HH:mm:ss:SSS";
|
||||
DateFormat formatter = new SimpleDateFormat(FORMAT);
|
||||
|
||||
@Override
|
||||
public CANPacket readLine(String line, String fileName, int lineIndex) {
|
||||
if (line.startsWith("***"))
|
||||
return null;
|
||||
String trimmed = line.trim();
|
||||
if (trimmed.isEmpty())
|
||||
return null;
|
||||
String[] tokens = trimmed.split("\\s+");
|
||||
if (tokens.length < 7)
|
||||
throw new IllegalStateException("Unexpected " + Arrays.toString(tokens));
|
||||
String hexId = tokens[3];
|
||||
String lenghtString = tokens[5];
|
||||
|
||||
int sid = Integer.parseInt(hexId.substring(2), 16);
|
||||
int size = Integer.parseInt(lenghtString);
|
||||
|
||||
long timeStamp;
|
||||
byte[] data = CANLineReader.readHexArray(tokens, 6, size);
|
||||
try {
|
||||
Date date = formatter.parse(tokens[0]);
|
||||
timeStamp = date.getTime();
|
||||
} catch (ParseException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return new CANPacket(timeStamp, sid, data);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RallySandbox {
|
||||
public static void main(String[] args) throws IOException {
|
||||
Launcher.main(new String[]{
|
||||
"C:\\stuff\\rusefi_documentation\\OEM-Docs\\Mitsubishi\\2009-rallyart",
|
||||
Launcher.FILENAME_SUFFIX_PROPERTY,
|
||||
".log",
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.rusefi.can.reader.impl;
|
||||
|
||||
import com.rusefi.can.CANPacket;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class BusMasterReaderTest {
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
String line = "21:27:52:3456 Rx 1 0x309 s 7 47 D8 7F D4 A8 00 05 ";
|
||||
BufferedReader reader = new BufferedReader(new StringReader(line));
|
||||
CANPacket packet = BusMasterReader.INSTANCE.readLine(reader.readLine());
|
||||
assertEquals(packet.getData().length, 7);
|
||||
assertEquals(packet.getData()[0], 0x47);
|
||||
assertEquals(packet.getData()[6], 0x05);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue