Compare commits
2 Commits
77459117ec
...
1e9efdfa6d
Author | SHA1 | Date |
---|---|---|
rusefillc | 1e9efdfa6d | |
rusefillc | 85b97ead7b |
|
@ -1,3 +1,9 @@
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
|
id 'java-library'
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
api rootProject
|
||||||
|
api project(':peak-can-basic')
|
||||||
}
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.rusefi.can;
|
||||||
|
|
||||||
|
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> logFileContent, PCANBasic pcan) throws InterruptedException {
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.rusefi.io.can;
|
||||||
|
|
||||||
|
|
||||||
|
import peak.can.basic.*;
|
||||||
|
|
||||||
|
import static peak.can.basic.TPCANMessageType.PCAN_MESSAGE_STANDARD;
|
||||||
|
|
||||||
|
public class PCanHelper {
|
||||||
|
public static final TPCANHandle CHANNEL = TPCANHandle.PCAN_USBBUS1;
|
||||||
|
|
||||||
|
// @NotNull
|
||||||
|
public static PCANBasic create() {
|
||||||
|
PCANBasic can = new PCANBasic();
|
||||||
|
can.initializeAPI();
|
||||||
|
return can;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TPCANStatus init(PCANBasic can) {
|
||||||
|
return can.Initialize(CHANNEL, TPCANBaudrate.PCAN_BAUD_500K, TPCANType.PCAN_TYPE_NONE, 0, (short) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TPCANStatus send(PCANBasic can, int id, byte[] payLoad) {
|
||||||
|
//log.info(String.format("Sending id=%x %s", id, HexBinary.printByteArray(payLoad)));
|
||||||
|
TPCANMsg msg = new TPCANMsg(id, PCAN_MESSAGE_STANDARD.getValue(),
|
||||||
|
(byte) payLoad.length, payLoad);
|
||||||
|
return can.Write(CHANNEL, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PCANBasic createAndInit() {
|
||||||
|
PCANBasic pcan = create();
|
||||||
|
TPCANStatus initStatus = init(pcan);
|
||||||
|
if (initStatus != TPCANStatus.PCAN_ERROR_OK) {
|
||||||
|
System.out.println("TPCANStatus " + initStatus);
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
return pcan;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue