ReduxLib C++ 2023.1.0
Loading...
Searching...
No Matches
redux::canand::CANandAddress Class Reference

#include <CANandAddress.h>

Public Member Functions

 CANandAddress (CANBus &bus, uint8_t devType, uint8_t prodId, uint8_t devId)
 
 CANandAddress (uint8_t devType, uint8_t prodId, uint8_t devId)
 
bool MsgMatches (CANandMessage &msg)
 
bool SendCANMessage (uint8_t apiIndex, uint8_t *data, uint8_t length)
 

Detailed Description

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:

  1. A 5 bit device type (devType) that is product specific (the CANandcoder is 7 for "gear tooth sensor")
  2. an 8-bit manufacturer code unique to each vendor (the Redux code is 14)
  3. 10 bits of API identifier
  4. a 6-bit device number (devId) that is user-configurable so you 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 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 5 bit product API ID (prodID) that is generally product specific (the CANandcoder prodId is 0) and a 5 bit API index (apiIndex), which actually gets used for a device's CAN API.

The breakdown can be seen in the diagram provided below:

+-------------------+-------------------------------+-------------------+-----------------------+-------------------+
|      devType      | manufacturer ID   (redux=0xE) | apiclass (prodId) |        apiIndex       | 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 prodId
  • the devId
  • and the CAN bus the message was sent from, as different devices on different buses can share identical IDs

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.

Constructor & Destructor Documentation

◆ CANandAddress() [1/2]

redux::canand::CANandAddress::CANandAddress ( CANBus bus,
uint8_t  devType,
uint8_t  prodId,
uint8_t  devId 
)
inline

Constructor with explicit CAN bus.

Parameters
busthe CANBus the address is associated with.
devTypethe device type
prodIdthe product id
devIdthe device CAN id

◆ CANandAddress() [2/2]

redux::canand::CANandAddress::CANandAddress ( uint8_t  devType,
uint8_t  prodId,
uint8_t  devId 
)
inline

Constructor with implicit Rio CAN bus.

Parameters
devTypethe device type
prodIdthe product id
devIdthe device CAN id

Member Function Documentation

◆ MsgMatches()

bool redux::canand::CANandAddress::MsgMatches ( CANandMessage msg)
inline

Checks if a CAN message matches against the device type, product id, and device can id

Parameters
msga CANandMessage matching
Returns
if there is a match

◆ SendCANMessage()

bool redux::canand::CANandAddress::SendCANMessage ( uint8_t  apiIndex,
uint8_t *  data,
uint8_t  length 
)

Sends a CAN message to the CANandAddress.

Parameters
apiIndexthe API index the message should have (between 0-31 inclusive)
data1-8 bytes of payload, as an array or pointer
lengththe length of the the payload buffer
Returns
if the operation was successful

The documentation for this class was generated from the following file: