Class CanandDevice

All Implemented Interfaces:
Direct Known Subclasses:
Canandcoder, Canandcolor

public abstract class CanandDevice extends Object implements AutoCloseable
Base class for Redux CAN devices. The ReduxLib vendordep does all CAN message parsing in the Java/C++ classes themselves, rather than the driver. 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:
  • Field Details

  • Constructor Details

    • CanandDevice

      public CanandDevice()
      Default constructor that just adds the device to the incoming CAN message listener.
  • Method Details

    • handleMessage

      public abstract void handleMessage(CanandMessage msg)
      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 getAddress().

      msg - a CanandMessage representing the received message.
    • getAddress

      public abstract CanandAddress getAddress()
      Returns 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.

      the CanandAddress for the device.
    • preHandleMessage

      public void preHandleMessage(CanandMessage msg)
      Called before handleMessage(com.reduxrobotics.canand.CanandMessage) 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.
    • isConnected

      public boolean isConnected(double timeout)
      Checks whether or not the device has sent a message within the last timeout seconds.
      timeout - window to check for message updates in seconds
      true if there has been a message within the last timeout seconds, false if not
    • isConnected

      public boolean isConnected()
      Checks whether or not the device has sent a message within the last 2000 milliseconds.
      true if there has been a message within the last 2000 milliseconds, false if not
    • checkReceivedFirmwareVersion

      protected void 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.

    • getMinimumFirmwareVersion

      public CanandFirmwareVersion getMinimumFirmwareVersion()
      Returns the minimum firmware version this vendordep requires for this device. User-implmenting classes can return null to disable firmware checks.
      minimum firmware version
    • getFirmwareVersion

      public CanandFirmwareVersion getFirmwareVersion()
      Returns the firmware version received by the device. May return null if a firmware version has not been received from the device yet.
      the received firmware version or null
    • sendCANMessage

      public void sendCANMessage(int apiIndex, byte[] data)
      Directly sends a CAN message to the device.

      Implementing device classes should call this function to send messages to the device, or use getAddress().sendCANMessage(int, byte[]), which this aliases.

      apiIndex - the individual API index to value to send
      data - 1-8 byte bytes payload
    • toString

      public String toString()
      toString in class Object
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable