ReduxLib C++ 2024.1.1-beta0
Loading...
Searching...
No Matches
redux::canand::CanandDevice Class Referenceabstract

#include <CanandDevice.h>

Inheritance diagram for redux::canand::CanandDevice:
redux::sensors::canandcoder::Canandcoder redux::sensors::canandcolor::Canandcolor

Public Member Functions

virtual void HandleMessage (CanandMessage &msg)=0
 
virtual CanandAddressGetAddress ()=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)
 

Detailed Description

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.

Member Function Documentation

◆ CheckReceivedFirmwareVersion()

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.

◆ 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.

Implemented in redux::sensors::canandcolor::Canandcolor.

◆ GetDeviceClassName()

virtual std::string redux::canand::CanandDevice::GetDeviceClassName ( )
inlinevirtual

Returns a canonical class-wide device name.

Returns
std::string of a device type name

Reimplemented in redux::sensors::canandcolor::Canandcolor.

◆ 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()

virtual CanandFirmwareVersion redux::canand::CanandDevice::GetMinimumFirmwareVersion ( )
inlinevirtual

Returns the minimum firmware version this vendordep requires.

Returns
minimum firmware version

Reimplemented in redux::sensors::canandcolor::Canandcolor.

◆ 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
msga reference to a CanandMessage representing the received message. The message may not have lifetime outside the function call.

Implemented in redux::sensors::canandcolor::Canandcolor.

◆ 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
timeoutwindow 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
msga CanandMessage representing the received message.

◆ 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
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

◆ 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
msgIdthe individual API index to value to send
data1-8 byte payload std:span of std:byte

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