Class CANBuses

java.lang.Object
swervelib.core.parser.CANBuses

public final class CANBuses extends Object
Turns the canbus of a device in the JSON configuration into a CAN bus, the same way for every vendor.
  • Empty: the Systemcore CAN bus can_s0.
  • A bus number: "0" to "4" are the Systemcore CAN buses can_s0 to can_s4, so "1" is can_s1. "5" to "24" are the Motioncore CAN buses can_d0 to can_d19, following CANPort.
  • Anything else is a vendor specific CAN bus, such as the name of a CANivore for CTRE devices. Vendors that only use the Systemcore and Motioncore CAN buses reject it.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.wpilib.hardware.bus.CANPort
    CAN bus used when a device leaves canbus empty.
  • Method Summary

    Modifier and Type
    Method
    Description
    static Optional<org.wpilib.hardware.bus.CANPort>
    Get the CANPort for the canbus of a device.
    static org.wpilib.hardware.bus.CANPort
    requireCANPort(String canbus, String vendor)
    Get the CANPort for the canbus of a device from a vendor that only uses the Systemcore and Motioncore CAN buses.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT

      public static final org.wpilib.hardware.bus.CANPort DEFAULT
      CAN bus used when a device leaves canbus empty.
  • Method Details

    • getCANPort

      public static Optional<org.wpilib.hardware.bus.CANPort> getCANPort(String canbus)
      Get the CANPort for the canbus of a device.
      Parameters:
      canbus - canbus from the JSON configuration.
      Returns:
      The CANPort, or empty when canbus names a vendor specific CAN bus.
      Throws:
      IllegalArgumentException - if canbus is a bus number that is not a CANPort.
    • requireCANPort

      public static org.wpilib.hardware.bus.CANPort requireCANPort(String canbus, String vendor)
      Get the CANPort for the canbus of a device from a vendor that only uses the Systemcore and Motioncore CAN buses.
      Parameters:
      canbus - canbus from the JSON configuration.
      vendor - Vendor name, for the error message.
      Returns:
      The CANPort.
      Throws:
      IllegalArgumentException - if canbus is not a Systemcore or Motioncore CAN bus number.