diff --git a/playback/src/main/java/com/rusefi/io/can/CanSender.java b/playback/src/main/java/com/rusefi/io/can/CanSender.java new file mode 100644 index 0000000..bc8d52d --- /dev/null +++ b/playback/src/main/java/com/rusefi/io/can/CanSender.java @@ -0,0 +1,5 @@ +package com.rusefi.io.can; + +public interface CanSender { + void send(int id, byte[] payload); +} diff --git a/playback/src/main/java/com/rusefi/io/can/PCanHelper.java b/playback/src/main/java/com/rusefi/io/can/PCanHelper.java index 22d8adb..ca43363 100644 --- a/playback/src/main/java/com/rusefi/io/can/PCanHelper.java +++ b/playback/src/main/java/com/rusefi/io/can/PCanHelper.java @@ -9,7 +9,7 @@ public class PCanHelper { public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1; // @NotNull - public static PCANBasic create() { + public static PCANBasic createPCAN() { PCANBasic can = new PCANBasic(); can.initializeAPI(); return can; @@ -27,7 +27,7 @@ public static TPCANStatus send(PCANBasic can, int id, byte[] payLoad) { } public static PCANBasic createAndInit() { - PCANBasic pcan = create(); + PCANBasic pcan = createPCAN(); TPCANStatus initStatus = init(pcan); if (initStatus != TPCANStatus.PCAN_ERROR_OK) { System.out.println("TPCANStatus " + initStatus); @@ -35,4 +35,14 @@ public static PCANBasic createAndInit() { } return pcan; } + + public static CanSender create() { + PCANBasic pcan = createAndInit(); + return new CanSender() { + @Override + public void send(int id, byte[] payload) { + PCanHelper.send(pcan, id, payload); + } + }; + } } diff --git a/playback/src/main/java/com/rusefi/io/can/SocketCANHelper.java b/playback/src/main/java/com/rusefi/io/can/SocketCANHelper.java index 24bc32c..ef9d878 100644 --- a/playback/src/main/java/com/rusefi/io/can/SocketCANHelper.java +++ b/playback/src/main/java/com/rusefi/io/can/SocketCANHelper.java @@ -36,4 +36,14 @@ public static void send(int id, byte[] payload, RawCanChannel channel) { throw new IllegalStateException(e); } } + + public static CanSender create() { + RawCanChannel canChannel = createSocket(); + return new CanSender() { + @Override + public void send(int id, byte[] payload) { + SocketCANHelper.send(id, payload, canChannel); + } + }; + } }