mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
[hal] Add CAN Stream API to Java through JNI bindings (#4193)
The CAN Stream API allows defining an buffer to receive an arbitrary set of CAN messages, based on an ID and a mask. Messages are added to this queue separate of other CAN APIs. This means the messages can be receive without impacting other APIs such as vendor APIs. This enables things like detection of what devices are on the bus, or custom decoding, without using vendor APIs. Co-authored-by: Thad House <thadhouse1@gmail.com>
This commit is contained in:
35
hal/src/main/java/edu/wpi/first/hal/CANStreamMessage.java
Normal file
35
hal/src/main/java/edu/wpi/first/hal/CANStreamMessage.java
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
package edu.wpi.first.hal;
|
||||
|
||||
public class CANStreamMessage {
|
||||
@SuppressWarnings("MemberName")
|
||||
public final byte[] data = new byte[8];
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public int length;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public long timestamp;
|
||||
|
||||
@SuppressWarnings("MemberName")
|
||||
public int messageID;
|
||||
|
||||
/**
|
||||
* API used from JNI to set the data.
|
||||
*
|
||||
* @param length Length of packet in bytes.
|
||||
* @param messageID CAN message ID of the message.
|
||||
* @param timestamp CAN frame timestamp in microseconds.
|
||||
* @return Buffer containing CAN frame.
|
||||
*/
|
||||
@SuppressWarnings("PMD.MethodReturnsInternalArray")
|
||||
public byte[] setStreamData(int length, int messageID, long timestamp) {
|
||||
this.messageID = messageID;
|
||||
this.length = length;
|
||||
this.timestamp = timestamp;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
package edu.wpi.first.hal.can;
|
||||
|
||||
import edu.wpi.first.hal.CANStreamMessage;
|
||||
import edu.wpi.first.hal.JNIWrapper;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
@@ -24,4 +25,11 @@ public class CANJNI extends JNIWrapper {
|
||||
IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp);
|
||||
|
||||
public static native void getCANStatus(CANStatus status);
|
||||
|
||||
public static native int openCANStreamSession(int messageID, int messageIDMask, int maxMessages);
|
||||
|
||||
public static native void closeCANStreamSession(int sessionHandle);
|
||||
|
||||
public static native int readCANStreamSession(
|
||||
int sessionHandle, CANStreamMessage[] messages, int messagesToRead);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user