This commit is contained in:
rusefillc 2022-02-15 16:17:28 -05:00
parent 7fbcf37782
commit 25403d68de
11 changed files with 138 additions and 21 deletions

View File

@ -2,7 +2,7 @@ package com.rusefi.can;
import com.rusefi.can.decoders.PacketDecoder;
import com.rusefi.can.decoders.bmw.BmwRegistry;
import com.rusefi.can.reader.CANoeReader;
import com.rusefi.can.reader.impl.CANoeReader;
import java.io.FileWriter;
import java.io.IOException;
@ -10,7 +10,7 @@ import java.util.List;
public class CAN2TS {
public static void main(String[] args) throws IOException {
CANoeReader reader = new CANoeReader();
CANoeReader reader = CANoeReader.INSTANCE;
List<CANPacket> packetList = reader.readFile("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\Log2.log");

View File

@ -1,20 +1,21 @@
package com.rusefi.can;
import com.rusefi.can.decoders.bmw.Bmw192;
import com.rusefi.can.reader.CANoeReader;
import com.rusefi.can.reader.CANLineReader;
import com.rusefi.can.reader.impl.CANoeReader;
import java.io.IOException;
import java.util.List;
public class CanValidator {
public class CANoeCanValidator {
public static void main(String[] args) throws IOException {
validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\Log1.log");
validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\Log2.log");
CANLineReader reader = CANoeReader.INSTANCE;
validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\Log1.log", reader);
validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\Log2.log", reader);
}
private static void validate(String fileName) throws IOException {
CANoeReader reader = new CANoeReader();
public static void validate(String fileName, CANLineReader reader) throws IOException {
List<CANPacket> packetList = reader.readFile(fileName);
for (CANPacket packet : packetList) {

View File

@ -0,0 +1,17 @@
package com.rusefi.can;
import com.rusefi.can.reader.CANLineReader;
import com.rusefi.can.reader.impl.PcanReader;
import java.io.IOException;
public class PcanCanValidator {
public static void main(String[] args) throws IOException {
CANLineReader reader = PcanReader.INSTANCE;
CANoeCanValidator.validate("C:\\stuff\\rusefi_documentation\\OEM-Docs\\Bmw\\2003_7_Series_e65\\HeinrichG-V12-E65_ReverseEngineering\\E65-760-andrey-2021-dec-29-oem-reverse-drive-around-block.trc", reader);
}
}

View File

@ -11,7 +11,10 @@ import com.rusefi.can.decoders.AbstractPacketDecoder;
*/
public class Bmw192 extends AbstractPacketDecoder {
enum Value {
NOTHING
NOTHING,
NEUTRAL,
REVERSE,
DRIVE,
}
public static final int ID = 0x192;
@ -31,6 +34,19 @@ public class Bmw192 extends AbstractPacketDecoder {
if (packet.getUnsignedInt(0) == 0x6A && packet.getUnsignedInt(1) == 0)
return new PacketPayload(0, new SensorValue(SensorType.GEAR_CHANGE_REQUEST, Value.NOTHING.ordinal()));
if (packet.getUnsignedInt(0) == 0x6A && packet.getUnsignedInt(1) == 0x40)
return new PacketPayload(0, new SensorValue(SensorType.GEAR_CHANGE_REQUEST, Value.NOTHING.ordinal()));
if (packet.getUnsignedInt(0) == 0x6A && packet.getUnsignedInt(1) == 0x50)
return new PacketPayload(0, new SensorValue(SensorType.GEAR_CHANGE_REQUEST, Value.NOTHING.ordinal()));
if (packet.getUnsignedInt(0) == 0x47 && packet.getUnsignedInt(1) == 1)
return new PacketPayload(0, new SensorValue(SensorType.GEAR_CHANGE_REQUEST, Value.NEUTRAL.ordinal()));
if (packet.getUnsignedInt(0) == 0x2D && packet.getUnsignedInt(1) == 4)
return new PacketPayload(0, new SensorValue(SensorType.GEAR_CHANGE_REQUEST, Value.REVERSE.ordinal()));
if (packet.getUnsignedInt(0) == 0x74 && packet.getUnsignedInt(1) == 3)
return new PacketPayload(0, new SensorValue(SensorType.GEAR_CHANGE_REQUEST, Value.DRIVE.ordinal()));
throwUnexpected("unhandled", packet);

View File

@ -2,6 +2,18 @@ package com.rusefi.can.reader;
import com.rusefi.can.CANPacket;
import java.io.IOException;
import java.util.List;
public interface CANLineReader {
static byte[] readHexArray(String[] tokens, int start, int size) {
byte[] data = new byte[size];
for (int i = 0; i < size; i++)
data[i] = (byte) Integer.parseInt(tokens[start + i], 16);
return data;
}
CANPacket readLine(String line);
List<CANPacket> readFile(String fileName) throws IOException;
}

View File

@ -1,4 +0,0 @@
package com.rusefi.can.reader;
public class CanHackerReader {
}

View File

@ -1,6 +1,7 @@
package com.rusefi.can.reader;
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;
@ -10,7 +11,9 @@ import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;
public class CANoeReader implements CANLineReader {
public enum CANoeReader implements CANLineReader {
INSTANCE;
@Override
public CANPacket readLine(String line) {
if (line.contains("ErrorFrame"))
@ -18,16 +21,14 @@ public class CANoeReader implements CANLineReader {
String[] tokens = line.trim().split("\\s+");
double timeStamp = Double.parseDouble(tokens[0]);
int sid = Integer.parseInt(tokens[2], 16);
int counter = Integer.parseInt(tokens[5]);
int size = Integer.parseInt(tokens[5]);
byte[] data = new byte[counter];
for (int i = 0; i < counter; i++)
data[i] = (byte) Integer.parseInt(tokens[6 + i], 16);
byte[] data = CANLineReader.readHexArray(tokens, 6, size);
return new CANPacket(timeStamp, sid, data);
}
@Override
public List<CANPacket> readFile(String fileName) throws IOException {
List<CANPacket> result = new ArrayList<>();
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {

View File

@ -0,0 +1,4 @@
package com.rusefi.can.reader.impl;
public class CanHackerReader {
}

View File

@ -0,0 +1,49 @@
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.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;
public enum PcanReader implements CANLineReader {
INSTANCE;
@Override
public CANPacket readLine(String line) {
line = line.trim();
if (line.startsWith(";"))
return null;
String[] tokens = line.split("\\s+");
double timeStamp = Double.parseDouble(tokens[1]);
int sid = Integer.parseInt(tokens[3], 16);
int size = Integer.parseInt(tokens[5]);
byte[] data = CANLineReader.readHexArray(tokens, 6, size);
return new CANPacket(timeStamp, sid, data);
}
@Override
public List<CANPacket> readFile(String fileName) throws IOException {
List<CANPacket> result = new ArrayList<>();
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
stream.forEach(new Consumer<String>() {
@Override
public void accept(String s) {
CANPacket packet = readLine(s);
if (packet != null)
result.add(packet);
}
});
return result;
}
}
}

View File

@ -1,7 +1,8 @@
package com.rusefi.can.reader;
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;

View File

@ -0,0 +1,20 @@
package com.rusefi.can.reader.impl;
import com.rusefi.can.CANPacket;
import com.rusefi.can.decoders.bmw.Bmw192;
import com.rusefi.can.reader.CANLineReader;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class PcanReaderTest {
@Test
public void testLine() {
CANLineReader reader = new PcanReader();
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());
assertEquals(0x80, packet.getUnsigned(2));
}
}