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