Compare commits
4 Commits
71d5016554
...
6697d24878
Author | SHA1 | Date |
---|---|---|
rusefillc | 6697d24878 | |
rusefillc | 632187c3ac | |
rusefillc | ad22f0a097 | |
rusefillc | ae97098340 |
|
@ -19,10 +19,10 @@ jobs:
|
|||
run: javac -version
|
||||
|
||||
- name: Gradle
|
||||
run: bash gradlew test
|
||||
run: ./gradlew test
|
||||
|
||||
- name: Gradle
|
||||
run: bash gradlew jar
|
||||
run: ./gradlew jar
|
||||
|
||||
- name: Upload .jar file
|
||||
uses: actions/upload-artifact@v2
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
.gradle
|
||||
/build
|
||||
build
|
||||
.idea
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 95ecb90a0e5c4c6082548191f91a4181b143698b
|
||||
Subproject commit 5bfc8e4c4c00f51996a0d1a501cbfc6e27c04ca7
|
|
@ -1,34 +1,24 @@
|
|||
package com.rusefi.can;
|
||||
|
||||
import com.rusefi.io.can.PCanHelper;
|
||||
import peak.can.basic.PCANBasic;
|
||||
import peak.can.basic.TPCANStatus;
|
||||
import com.rusefi.io.can.CanSender;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class CanPacketSender {
|
||||
public static void sendMessagesOut(List<CANPacket> logFileContent, PCANBasic pcan) throws InterruptedException {
|
||||
public static void sendMessagesOut(List<CANPacket> packets, CanSender sender) {
|
||||
int okCounter = 0;
|
||||
|
||||
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());
|
||||
}
|
||||
for (CANPacket packet : packets) {
|
||||
boolean wasSendOk = sender.send(packet.getId(), packet.getData());
|
||||
|
||||
if (status == TPCANStatus.PCAN_ERROR_OK) {
|
||||
if (wasSendOk) {
|
||||
okCounter++;
|
||||
} else {
|
||||
System.out.println("Error sending " + status);
|
||||
}
|
||||
|
||||
if (okCounter % 1000 == 0) {
|
||||
System.out.println(new Date() + ": Total " + okCounter + " OK messages");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package com.rusefi.io.can;
|
||||
|
||||
public interface CanSender {
|
||||
void send(int id, byte[] payload);
|
||||
boolean send(int id, byte[] payload);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ public class PCanHelper {
|
|||
PCANBasic pcan = createPCAN();
|
||||
TPCANStatus initStatus = init(pcan);
|
||||
if (initStatus != TPCANStatus.PCAN_ERROR_OK) {
|
||||
System.out.println("TPCANStatus " + initStatus);
|
||||
System.out.println("createAndInit: *** ERROR *** TPCANStatus " + initStatus);
|
||||
System.exit(-1);
|
||||
}
|
||||
return pcan;
|
||||
|
@ -38,11 +38,24 @@ public class PCanHelper {
|
|||
|
||||
public static CanSender create() {
|
||||
PCANBasic pcan = createAndInit();
|
||||
return new CanSender() {
|
||||
@Override
|
||||
public void send(int id, byte[] payload) {
|
||||
PCanHelper.send(pcan, id, payload);
|
||||
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);
|
||||
}
|
||||
|
||||
boolean isHappy = status == TPCANStatus.PCAN_ERROR_OK;
|
||||
if (!isHappy) {
|
||||
System.out.println("Error sending " + status);
|
||||
}
|
||||
return isHappy;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,8 +41,9 @@ public class SocketCANHelper {
|
|||
RawCanChannel canChannel = createSocket();
|
||||
return new CanSender() {
|
||||
@Override
|
||||
public void send(int id, byte[] payload) {
|
||||
public boolean send(int id, byte[] payload) {
|
||||
SocketCANHelper.send(id, payload, canChannel);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue