Package com.reduxrobotics.canand
Class CanandAddress
java.lang.Object
com.reduxrobotics.canand.CanandAddress
Class representing the exact combination of CAN bus, product IDs, and device IDs that uniquely
correspond to a Redux CAN device on a robot.
The full 29-bit CAN ID that actually gets put on the bus can be broken down into four components:
- A 5 bit device type (devType) that is product specific (the Canandmag is 7 for "gear tooth sensor")
- an 8-bit manufacturer code unique to each vendor (the Redux code is 14)
- 10 bits of API identifier
- a 6-bit device number (devId) that is user-configurable so one can have multiple of a device on a bus (this is what the "CAN Id" in robot code and vendor tuners usually refer to)
The breakdown can be seen in the diagram provided below:
+-------------------+-------------------------------+-------+-------------------------------+-----------------------+ | Device Type | Manufacturer ID (redux=0xE) | Page | API Index | Device ID (devID) | +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+ | 28| 27| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0| +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+Documentation on what each apiIndex value does as well as DBCs for Redux devices is available at https://docs.reduxrobotics.com/
In summary, to check if an incoming CAN message is from the device the CanandAddress represents, it needs to check:
- the devType
- the devId
- and the CAN bus the message was sent from, as different devices on different buses can share identical IDs
Subclasses of CanandDevice
will use this class for CAN i/o to a device, as this class
provides a method to send CAN packets to the device it describes, and CanandEventLoop
uses it to determine which messages to give to CanandDevice.handleMessage(com.reduxrobotics.canand.CanandMessage)
by checking
them against msgMatches(com.reduxrobotics.canand.CanandMessage)
, yielding an asynchronous method of receiving packets.
-
Constructor Summary
ConstructorDescriptionCanandAddress
(int devType, int devId) Constructor with implicit Rio CAN bus.CanandAddress
(CANBus bus, int devType, int devId) Constructor with explicit CAN bus. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the user-settable device ID.int
Returns the 5-bit device type.boolean
msgMatches
(CanandMessage msg) Checks if a CAN message matches against the device type, product id, and device can idboolean
sendCANMessage
(int apiIndex, byte[] data) Sends a CAN message to the CanandAddress.boolean
sendCANMessage
(int apiIndex, long data, int length) Sends a CAN message to the CanandAddress.
-
Constructor Details
-
CanandAddress
Constructor with explicit CAN bus.- Parameters:
bus
- the CANBus the address is associated withdevType
- the device typedevId
- the device CAN id
-
CanandAddress
public CanandAddress(int devType, int devId) Constructor with implicit Rio CAN bus.- Parameters:
devType
- the device typedevId
- the device CAN id
-
-
Method Details
-
msgMatches
Checks if a CAN message matches against the device type, product id, and device can id- Parameters:
msg
- a CanandMessage matching- Returns:
- if there is a match
-
sendCANMessage
public boolean sendCANMessage(int apiIndex, byte[] data) Sends a CAN message to the CanandAddress.- Parameters:
apiIndex
- the API index the message should have (between 0-255 inclusive)data
- 0-8 bytes of payload -- length of array will correspond to length of packet- Returns:
- if the operation was successful
-
sendCANMessage
public boolean sendCANMessage(int apiIndex, long data, int length) Sends a CAN message to the CanandAddress.- Parameters:
apiIndex
- the API index the message should have (between 0-255 inclusive)data
- 0-8 bytes of payload -- encoded as little endian long (lower bits == lower bytes)length
- length of payload [0..8] inclusive- Returns:
- if the operation was successful
-
getDeviceType
public int getDeviceType()Returns the 5-bit device type.- Returns:
- the device type
-
getDeviceId
public int getDeviceId()Returns the user-settable device ID.- Returns:
- the device ID
-