SocketCAN sender
This commit is contained in:
parent
1e9efdfa6d
commit
e05d02475f
|
@ -7,9 +7,11 @@ apply from: 'dependencies.gradle'
|
||||||
group 'org.rusefi'
|
group 'org.rusefi'
|
||||||
version '0.11-SNAPSHOT'
|
version '0.11-SNAPSHOT'
|
||||||
|
|
||||||
|
allprojects {
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation libs.snakeyaml
|
implementation libs.snakeyaml
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
javaCanVersion=3.2.4
|
|
@ -6,4 +6,6 @@ plugins {
|
||||||
dependencies {
|
dependencies {
|
||||||
api rootProject
|
api rootProject
|
||||||
api project(':peak-can-basic')
|
api project(':peak-can-basic')
|
||||||
|
api group: 'tel.schich', name: 'javacan-core', version: "$javaCanVersion"
|
||||||
|
api group: 'tel.schich', name: 'javacan-core', version: "$javaCanVersion", classifier: 'x86_64'
|
||||||
}
|
}
|
|
@ -0,0 +1,39 @@
|
||||||
|
package com.rusefi.io.can;
|
||||||
|
|
||||||
|
import com.sun.istack.internal.NotNull;
|
||||||
|
import tel.schich.javacan.CanChannels;
|
||||||
|
import tel.schich.javacan.CanFrame;
|
||||||
|
import tel.schich.javacan.NetworkDevice;
|
||||||
|
import tel.schich.javacan.RawCanChannel;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static tel.schich.javacan.CanFrame.FD_NO_FLAGS;
|
||||||
|
import static tel.schich.javacan.CanSocketOptions.RECV_OWN_MSGS;
|
||||||
|
|
||||||
|
public class SocketCANHelper {
|
||||||
|
@NotNull
|
||||||
|
public static RawCanChannel createSocket() {
|
||||||
|
final RawCanChannel socket;
|
||||||
|
try {
|
||||||
|
NetworkDevice canInterface = NetworkDevice.lookup(System.getProperty("CAN_DEVICE_NAME", "can0"));
|
||||||
|
socket = CanChannels.newRawChannel();
|
||||||
|
socket.bind(canInterface);
|
||||||
|
|
||||||
|
socket.configureBlocking(true); // we want reader thread to wait for messages
|
||||||
|
socket.setOption(RECV_OWN_MSGS, false);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException("Error looking up", e);
|
||||||
|
}
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void send(int id, byte[] payload, RawCanChannel channel) {
|
||||||
|
CanFrame packet = CanFrame.create(id, FD_NO_FLAGS, payload);
|
||||||
|
try {
|
||||||
|
channel.write(packet);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IllegalStateException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue