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"
  • Field Details

  • Constructor Details

    • CANJNI

      public CANJNI()
      Default constructor.
  • Method Details

    • FRCNetCommCANSessionMuxSendMessage

      public static void FRCNetCommCANSessionMuxSendMessage(int messageID, byte[] data, int periodMs)
      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, use CAN_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 for
      timeStamp - the packet received timestamp (based off of CLOCK_MONOTONIC) (output parameter).
      Returns:
      The data bytes of the received message.
    • getCANStatus

      public static void getCANStatus(CANStatus status)
      Retrieves the current status of the CAN bus.
      Parameters:
      status - The CANStatus object to hold the retrieved status.
    • openCANStreamSession

      public static int openCANStreamSession(int messageID, int messageIDMask, int maxMessages)
      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

      public static void closeCANStreamSession(int sessionHandle)
      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.