Class CanandMessage

java.lang.Object
com.reduxrobotics.canand.CanandMessage

public class CanandMessage extends Object
Class that represents a CAN message received from the Redux CanandEventLoop This class is generally (re)initialized by updateFromByteBuf(java.nio.ByteBuffer) with a ByteBuffer from the JNI via CanandEventLoop. From there, it is then passed into CanandDevice.handleMessage(com.reduxrobotics.canand.CanandMessage) through the event loop.

To avoid garbage collection/heap allocation, the CanandMessage object passed into handleMessage() gets reused and has its contents overwritten upon receipt of a new CAN message. To hold onto the contained values for longer, use the copy constructor to create a new object.

Of particular note are getData() to read the packet's data and getApiIndex() to see what type of packet it is.

  • Constructor Details

    • CanandMessage

      public CanandMessage()
      Construct a new CanandMessage from nothing (to be filled in later.)
    • CanandMessage

      public CanandMessage(CanandMessage other)
      Copy constructor
      Parameters:
      other - other object to copy values from
  • Method Details

    • getId

      public int getId()
      Gets the full 29-bit CAN message id. A summary of how the CAN message id works is described in CanandAddress.
      Returns:
      The full 29-bit message id.
    • getApiIndex

      public int getApiIndex()
      Gets the 5-bit CAN API index. This is the value that generally describes what type of CAN message was sent.
      Returns:
      the CAN API index.
    • getDeviceId

      public int getDeviceId()
      Gets the 6-bit CAN Device id. This is the user-adjustible "CAN Id" of the associated CAN device in question.
      Returns:
      the device id.
    • getApiPage

      public int getApiPage()
      Gets the 5-bit Product ID / API class. Product ID/ device type combinations will be unique to a Redux product.
      Returns:
      the product id.
    • getDeviceType

      public int getDeviceType()
      Gets the 5-bit device type code Product ID/ device type combinations will be unique to a Redux product.
      Returns:
      the device type code.
    • getTimestamp

      public double getTimestamp()
      Gets the CAN message timestamp, in seconds. The time base is relative to the FPGA timestamp.
      Returns:
      timestamp in seconds.
    • getData

      public byte[] getData()
      Gets the CAN message payload (up to 8 bytes). The length of the array does not correspond to the actual length of valid data. To fetch the associated data length code, use getLength()
      Returns:
      array of bytes that is 8 bytes long.
    • getDataAsLong

      public long getDataAsLong()
      Gets the CAN message payload as a long. The length of the array does not correspond to the actual length of valid data. This will also not work for FD packets >8 bytes long. To fetch the associated data length code, use getLength()
      Returns:
      long
    • getLength

      public int getLength()
      Gets the length of the CAN message's data in bytes.
      Returns:
      length (1-8)
    • getBus

      public CANBus getBus()
      Gets an object representing the CAN bus that received the message
      Returns:
      CANBus object