Package edu.wpi.first.hal.can
Class CANJNI
java.lang.Object
edu.wpi.first.hal.JNIWrapper
edu.wpi.first.hal.can.CANJNI
CAN API HAL JNI Functions.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class edu.wpi.first.hal.JNIWrapper
JNIWrapper.Helper -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMask for "is frame 11 bits" in message ID.static final intMask for "is frame remote" in message ID.static final intFlag for sending a CAN message once.static final intFlag for stopping periodic CAN message sends. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcloseCANStreamSession(int sessionHandle) Closes a CAN stream session.static voidgetCANStatus(int busId, CANStatus status) Retrieves the current status of the CAN bus.static intopenCANStreamSession(int busId, int messageId, int messageIDMask, int maxMessages) Opens a new CAN stream session for receiving CAN messages with specified filters.static intreadCANStreamSession(int sessionHandle, CANStreamMessage[] messages, int messagesToRead) Reads messages from a CAN stream session.static intreceiveMessage(int busId, int messageId, CANReceiveMessage message) Receives a CAN message.static intsendMessage(int busId, int messageId, byte[] data, int dataLength, int flags, int periodMs) Sends a CAN message.Methods inherited from class edu.wpi.first.hal.JNIWrapper
forceLoad, suppressUnused
-
Field Details
-
CAN_SEND_PERIOD_NO_REPEAT
Flag for sending a CAN message once.- See Also:
-
CAN_SEND_PERIOD_STOP_REPEATING
Flag for stopping periodic CAN message sends.- See Also:
-
CAN_IS_FRAME_REMOTE
Mask for "is frame remote" in message ID.- See Also:
-
CAN_IS_FRAME_11BIT
Mask for "is frame 11 bits" in message ID.- See Also:
-
-
Constructor Details
-
CANJNI
public CANJNI()Default constructor.
-
-
Method Details
-
sendMessage
public static int sendMessage(int busId, int messageId, byte[] data, int dataLength, int flags, int periodMs) Sends a CAN message.- Parameters:
busId- The bus ID.messageId- The ID of the CAN message.data- the data to send.dataLength- the length of data to sendflags- the message flagsperiodMs- The period in milliseconds at which to send the message, useCAN_SEND_PERIOD_NO_REPEATfor a single send.- Returns:
- send status, 0 on success.
-
receiveMessage
Receives a CAN message.- Parameters:
busId- The bus ID.messageId- message id to look for.message- The message.- Returns:
- receive status, 0 on success.
-
getCANStatus
Retrieves the current status of the CAN bus.- Parameters:
busId- The bus ID.status- The CANStatus object to hold the retrieved status.
-
openCANStreamSession
public static int openCANStreamSession(int busId, int messageId, int messageIDMask, int maxMessages) Opens a new CAN stream session for receiving CAN messages with specified filters.- Parameters:
busId- The bus ID.messageId- The CAN messageId to match against. The bits of the messageId are bitwise ANDed with the messageIDMask.messageIDMask- The CAN messageIDMask is a bit-wise mask of bits in the messageId to match against. This allows matching against multiple frames. For example, providing an messageId of 0x2050001 and a mask of 0x1FFF003F would match all REV motor controller frames for a device with CAN ID 1. Providing a mask of 0x1FFFFFFF means that only the exact messageId will be matched. Providing a mask of 0 would match any frame of any type.maxMessages- The maximum number of messages that can be buffered in the session.- Returns:
- The handle to the opened CAN stream session.
-
closeCANStreamSession
Closes a CAN stream session.- Parameters:
sessionHandle- The handle of the CAN stream session to be closed.
-
readCANStreamSession
public static int readCANStreamSession(int sessionHandle, CANStreamMessage[] messages, int messagesToRead) throws CANStreamOverflowException Reads messages from a CAN stream session.- Parameters:
sessionHandle- The handle of the CAN stream session.messages- An array to hold the CANStreamMessage objects (output parameter).messagesToRead- The number of messages to read from the session.- Returns:
- The number of messages read into the buffer
- Throws:
CANStreamOverflowException- If the number of messages to read exceeds the capacity of the provided messages array.
-