ReduxLib C++ 2024.3.2
|
#include <CanandAddress.h>
Public Member Functions | |
CanandAddress (CANBus &bus, uint8_t devType, uint8_t devId) | |
CanandAddress (uint8_t devType, uint8_t devId) | |
bool | MsgMatches (CanandMessage &msg) |
bool | SendCANMessage (uint16_t apiIndex, uint8_t *data, uint8_t length) |
uint8_t | GetDeviceType () |
uint8_t | GetDeviceId () |
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:
The WPILib docs elaborate on this in a bit more detail.
Of note is that it breaks down the 10-bit API identifier into a 6-bit API class and 4-bit API index. Redux products, however, break it down into a 2 bit API page (page) and an 8 bit API index (apiIndex), which actually gets used for a device's message API.
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:
to ensure they all match, leaving the apiIndex to be parsed by device class code. (The manufacturer ID is filtered for in the native driver portion of ReduxLib.)
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 the internal event loop uses it to determine which messages to give to CanandDevice::HandleMessage by checking them against MsgMatches, yielding an asynchronous method of receiving packets.
|
inline |
Constructor with explicit CAN bus.
bus | the CANBus the address is associated with. |
devType | the device type |
devId | the device CAN id |
|
inline |
Constructor with implicit Rio CAN bus.
devType | the device type |
devId | the device CAN id |
|
inline |
Returns the user-settable device ID.
|
inline |
Returns the 5-bit device type.
|
inline |
Checks if a CAN message matches against the device type, product id, and device can id
msg | a CanandMessage matching |
bool redux::canand::CanandAddress::SendCANMessage | ( | uint16_t | apiIndex, |
uint8_t * | data, | ||
uint8_t | length | ||
) |
Sends a CAN message to the CanandAddress.
apiIndex | the API index the message should have (between 0-1023 inclusive, optionally ORed with 512 or 256) |
data | 1-8 bytes of payload, as an array or pointer |
length | the length of the the payload buffer |