Compare commits

..

No commits in common. "6697d2487867451f3b91b09695b0a602288507ce" and "71d5016554899aca938f7bb618a8ecf20b9a9c5e" have entirely different histories.

8 changed files with 26 additions and 30 deletions

View File

@ -19,10 +19,10 @@ jobs:
run: javac -version
- name: Gradle
run: ./gradlew test
run: bash gradlew test
- name: Gradle
run: ./gradlew jar
run: bash gradlew jar
- name: Upload .jar file
uses: actions/upload-artifact@v2

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
.gradle
build
/build
.idea

@ -1 +1 @@
Subproject commit 5bfc8e4c4c00f51996a0d1a501cbfc6e27c04ca7
Subproject commit 95ecb90a0e5c4c6082548191f91a4181b143698b

0
gradlew vendored Executable file → Normal file
View File

View File

@ -1,24 +1,34 @@
package com.rusefi.can;
import com.rusefi.io.can.CanSender;
import com.rusefi.io.can.PCanHelper;
import peak.can.basic.PCANBasic;
import peak.can.basic.TPCANStatus;
import java.util.Date;
import java.util.List;
public class CanPacketSender {
public static void sendMessagesOut(List<CANPacket> packets, CanSender sender) {
public static void sendMessagesOut(List<CANPacket> logFileContent, PCANBasic pcan) throws InterruptedException {
int okCounter = 0;
for (CANPacket packet : packets) {
boolean wasSendOk = sender.send(packet.getId(), packet.getData());
for (CANPacket packet : logFileContent) {
TPCANStatus status = PCanHelper.send(pcan, packet.getId(), packet.getData());
if (status == TPCANStatus.PCAN_ERROR_XMTFULL || status == TPCANStatus.PCAN_ERROR_QXMTFULL) {
Thread.sleep(10);
// System.out.println(String.format("Let's retry ID=%x", packet.getId()) + " OK=" + okCounter);
status = PCanHelper.send(pcan, packet.getId(), packet.getData());
}
if (wasSendOk) {
if (status == TPCANStatus.PCAN_ERROR_OK) {
okCounter++;
} else {
System.out.println("Error sending " + status);
}
if (okCounter % 1000 == 0) {
System.out.println(new Date() + ": Total " + okCounter + " OK messages");
}
}
}
}

View File

@ -1,5 +1,5 @@
package com.rusefi.io.can;
public interface CanSender {
boolean send(int id, byte[] payload);
void send(int id, byte[] payload);
}

View File

@ -30,7 +30,7 @@ public class PCanHelper {
PCANBasic pcan = createPCAN();
TPCANStatus initStatus = init(pcan);
if (initStatus != TPCANStatus.PCAN_ERROR_OK) {
System.out.println("createAndInit: *** ERROR *** TPCANStatus " + initStatus);
System.out.println("TPCANStatus " + initStatus);
System.exit(-1);
}
return pcan;
@ -38,24 +38,11 @@ public class PCanHelper {
public static CanSender create() {
PCANBasic pcan = createAndInit();
return (id, payload) -> {
TPCANStatus status = send(pcan, id, payload);
if (status == TPCANStatus.PCAN_ERROR_XMTFULL || status == TPCANStatus.PCAN_ERROR_QXMTFULL) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
// System.out.println(String.format("Let's retry ID=%x", packet.getId()) + " OK=" + okCounter);
status = send(pcan, id, payload);
return new CanSender() {
@Override
public void send(int id, byte[] payload) {
PCanHelper.send(pcan, id, payload);
}
boolean isHappy = status == TPCANStatus.PCAN_ERROR_OK;
if (!isHappy) {
System.out.println("Error sending " + status);
}
return isHappy;
};
}
}

View File

@ -41,9 +41,8 @@ public class SocketCANHelper {
RawCanChannel canChannel = createSocket();
return new CanSender() {
@Override
public boolean send(int id, byte[] payload) {
public void send(int id, byte[] payload) {
SocketCANHelper.send(id, payload, canChannel);
return true;
}
};
}