Package com.reduxrobotics.canand
Class CanandMessage
java.lang.Object
com.reduxrobotics.canand.CanandMessage
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 Summary
ConstructorDescriptionConstruct a newCanandMessage
from nothing (to be filled in later.)CanandMessage
(CanandMessage other) Copy constructor -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the 5-bit CAN API index.int
Gets the 5-bit Product ID / API class.getBus()
Gets an object representing the CAN bus that received the messagebyte[]
getData()
Gets the CAN message payload (up to 8 bytes).long
Gets the CAN message payload as a long.int
Gets the 6-bit CAN Device id.int
Gets the 5-bit device type code Product ID/ device type combinations will be unique to a Redux product.int
getId()
Gets the full 29-bit CAN message id.int
Gets the length of the CAN message's data in bytes.double
Gets the CAN message timestamp, in seconds.
-
Constructor Details
-
CanandMessage
public CanandMessage()Construct a newCanandMessage
from nothing (to be filled in later.) -
CanandMessage
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 inCanandAddress
.- 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, usegetLength()
- 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, usegetLength()
- Returns:
- long
-
getLength
public int getLength()Gets the length of the CAN message's data in bytes.- Returns:
- length (1-8)
-
getBus
Gets an object representing the CAN bus that received the message- Returns:
- CANBus object
-