Package edu.wpi.first.hal.can
Class CANJNI
java.lang.Object
edu.wpi.first.hal.JNIWrapper
edu.wpi.first.hal.can.CANJNI
public class CANJNI extends JNIWrapper
CAN API HAL JNI Functions.
- See Also:
- "hal/CAN.h"
-
Nested Class Summary
-
Field Summary
Fields Modifier and Type Field Description static int
CAN_IS_FRAME_11BIT
Mask for "is frame 11 bits" in message ID.static int
CAN_IS_FRAME_REMOTE
Mask for "is frame remote" in message ID.static int
CAN_SEND_PERIOD_NO_REPEAT
Flag for sending a CAN message once.static int
CAN_SEND_PERIOD_STOP_REPEATING
Flag for stopping periodic CAN message sends. -
Constructor Summary
Constructors Constructor Description CANJNI()
Default constructor. -
Method Summary
Modifier and Type Method Description static void
closeCANStreamSession(int sessionHandle)
Closes a CAN stream session.static byte[]
FRCNetCommCANSessionMuxReceiveMessage(IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp)
Receives a CAN message.static void
FRCNetCommCANSessionMuxSendMessage(int messageID, byte[] data, int periodMs)
Sends a CAN message.static void
getCANStatus(CANStatus status)
Retrieves the current status of the CAN bus.static int
openCANStreamSession(int messageID, int messageIDMask, int maxMessages)
Opens a new CAN stream session for receiving CAN messages with specified filters.static int
readCANStreamSession(int sessionHandle, CANStreamMessage[] messages, int messagesToRead)
Reads messages from a CAN stream session.
-
Field Details
-
CAN_SEND_PERIOD_NO_REPEAT
Flag for sending a CAN message once.- See Also:
- Constant Field Values
-
CAN_SEND_PERIOD_STOP_REPEATING
Flag for stopping periodic CAN message sends.- See Also:
- Constant Field Values
-
CAN_IS_FRAME_REMOTE
Mask for "is frame remote" in message ID.- See Also:
- Constant Field Values
-
CAN_IS_FRAME_11BIT
Mask for "is frame 11 bits" in message ID.- See Also:
- Constant Field Values
-
-
Constructor Details
-
Method Details
-
FRCNetCommCANSessionMuxSendMessage
Sends a CAN message.- Parameters:
messageID
- The ID of the CAN message.data
- The data bytes to be sent.periodMs
- The period in milliseconds at which to send the message, useCAN_SEND_PERIOD_NO_REPEAT
for a single send.
-
FRCNetCommCANSessionMuxReceiveMessage
public static byte[] FRCNetCommCANSessionMuxReceiveMessage(IntBuffer messageID, int messageIDMask, ByteBuffer timeStamp)Receives a CAN message.- Parameters:
messageID
- store for the received message ID (output parameter).messageIDMask
- the message ID mask to look fortimeStamp
- the packet received timestamp (based off of CLOCK_MONOTONIC) (output parameter).- Returns:
- The data bytes of the received message.
-
getCANStatus
Retrieves the current status of the CAN bus.- Parameters:
status
- The CANStatus object to hold the retrieved status.
-
openCANStreamSession
Opens a new CAN stream session for receiving CAN messages with specified filters.- Parameters:
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 CANStreamOverflowExceptionReads 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.
-