ReduxLib C++ 2024.2.0
|
#include <CanandDevice.h>
Public Member Functions | |
virtual void | HandleMessage (CanandMessage &msg)=0 |
virtual CanandAddress & | GetAddress ()=0 |
bool | IsConnected (units::second_t timeout=2_s) |
virtual std::string | GetDeviceClassName () |
std::string | GetDeviceName () |
virtual void | PreHandleMessage (CanandMessage &msg) |
void | CheckReceivedFirmwareVersion () |
virtual CanandFirmwareVersion | GetMinimumFirmwareVersion () |
bool | SendCANMessage (uint8_t apiIndex, uint8_t *data, uint8_t length) |
template<std::size_t len> requires (len < 8U) | |
void | SendCANMessage (uint8_t msgId, std::span< std::byte, len > data) |
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:
void redux::canand::CanandDevice::CheckReceivedFirmwareVersion | ( | ) |
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.
|
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.
Implemented in redux::sensors::canandcolor::Canandcolor.
|
inlinevirtual |
Returns a canonical class-wide device name.
Reimplemented in redux::sensors::canandcolor::Canandcolor.
std::string redux::canand::CanandDevice::GetDeviceName | ( | ) |
Returns a nicely formatted name of the device, specific to its device address.
|
inlinevirtual |
Returns the minimum firmware version this vendordep requires.
Reimplemented in redux::sensors::canandcolor::Canandcolor.
|
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().
msg | a reference to a CanandMessage representing the received message. The message may not have lifetime outside the function call. |
Implemented in redux::sensors::canandcolor::Canandcolor.
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.
timeout | window to check for message updates in seconds. Default 2 |
|
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.
msg | a CanandMessage representing the received message. |
|
inline |
Sends a CAN message to the CanandAddress.
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 |
|
inline |
Send a CAN message directly to the device, but properly length checked.
msgId | the individual API index to value to send |
data | 1-8 byte payload std:span of std:byte |