#include <CanandDevice.h>
The base class for all CAN-communicating Redux Robotics device classes. The ReduxLib vendordep does all CAN message parsing in the Java/C++ classes themselves. CanandDevice provides general facilities for sending and receiving CAN messages (abstracted from the actual underlying buses) as well as helper functions and constants common for all Redux CAN products.
Classes implementing CanandDevice need to do the following:
-
Implement CanandDevice::getAddress (usually by instantiating a CanandAddress in the constructor and returning it)
-
Implement CanandDevice::HandleMessage which will be called asynchronously whenever new CAN messages matching the object's CanandAddress get received by the robot
-
Run redux::canand::AddCANListener(this) in the constructor so HandleMessage actually gets called at runtime
-
Run redux::canand::RemoveCANListener(this) in the destructor.
◆ CheckReceivedFirmwareVersion()
virtual void redux::canand::CanandDevice::CheckReceivedFirmwareVersion |
( |
| ) |
|
|
virtual |
Checks the received firmware version.
If no firmware version has been received, complain to the driver station about potentially missing devices from the bus.
If the reported firmware version is too old, also complain to the driver station.
◆ GetAddress()
virtual CanandAddress & redux::canand::CanandDevice::GetAddress |
( |
| ) |
|
|
pure virtual |
Returns the reference to the CanandAddress representing the combination of CAN bus and CAN device ID that this CanandDevice refers to.
Implementing device subclasses should likely construct a new CanandAddress in their constructor and return it here.
- Returns
- a reference to the CanandAddress for the device.
◆ GetDeviceClassName()
virtual std::string redux::canand::CanandDevice::GetDeviceClassName |
( |
| ) |
|
|
inlinevirtual |
Returns a canonical class-wide device name.
- Returns
- std::string of a device type name
◆ GetDeviceName()
std::string redux::canand::CanandDevice::GetDeviceName |
( |
| ) |
|
Returns a nicely formatted name of the device, specific to its device address.
- Returns
- std::string of a specific device name
◆ GetMinimumFirmwareVersion()
Returns the minimum firmware version this vendordep requires.
- Returns
- minimum firmware version
◆ HandleMessage()
virtual void redux::canand::CanandDevice::HandleMessage |
( |
CanandMessage & |
msg | ) |
|
|
pure virtual |
A callback called when a Redux CAN message is received and should be parsed. Subclasses of CanandDevice should override this to update their internal state accordingly.
HandleMessage will be called on all Redux CAN packets received by the vendordep that match the CanandAddress returned by CanandDevice::GetAddress().
- Parameters
-
msg | a reference to a CanandMessage representing the received message. The message may not have lifetime outside the function call. |
◆ IsConnected()
bool redux::canand::CanandDevice::IsConnected |
( |
units::second_t |
timeout = 2_s | ) |
|
Checks whether or not the device has sent a message within the last timeout seconds.
- Parameters
-
timeout | window to check for message updates in seconds. Default 2 |
- Returns
- true if there has been a message within the last timeout seconds, false if not
◆ PreHandleMessage()
virtual void redux::canand::CanandDevice::PreHandleMessage |
( |
CanandMessage & |
msg | ) |
|
|
virtual |
Called before HandleMessage gets called to run some common logic. (Namely, handling setting receives and last message times)
This function can be overridden to change or disable its logic.
- Parameters
-
◆ SendCANMessage() [1/2]
bool redux::canand::CanandDevice::SendCANMessage |
( |
uint8_t |
apiIndex, |
|
|
uint8_t * |
data, |
|
|
uint8_t |
length |
|
) |
| |
|
inline |
Sends a CAN message to the CanandAddress.
- Parameters
-
apiIndex | the API index the message should have (between 0-31 inclusive) |
data | 1-8 bytes of payload, as an array or pointer |
length | the length of the the payload buffer |
- Returns
- if the operation was successful
◆ SendCANMessage() [2/2]
template<std::size_t len>
requires (len < 8U)
void redux::canand::CanandDevice::SendCANMessage |
( |
uint8_t |
msgId, |
|
|
std::span< std::byte, len > |
data |
|
) |
| |
|
inline |
Send a CAN message directly to the device, but properly length checked.
- Parameters
-
msgId | the individual API index to value to send |
data | 1-8 byte payload std:span of std:byte |
The documentation for this class was generated from the following file: