Skip to content

Commit

Permalink
CanSender
Browse files Browse the repository at this point in the history
  • Loading branch information
rusefillc committed Jan 6, 2024
1 parent e05d024 commit 5707eab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions playback/src/main/java/com/rusefi/io/can/CanSender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.rusefi.io.can;

public interface CanSender {
void send(int id, byte[] payload);
}
14 changes: 12 additions & 2 deletions playback/src/main/java/com/rusefi/io/can/PCanHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,12 +27,22 @@ 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);
System.exit(-1);
}
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);
}
};
}
}
10 changes: 10 additions & 0 deletions playback/src/main/java/com/rusefi/io/can/SocketCANHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
}
}

0 comments on commit 5707eab

Please sign in to comment.