Class BuildConstantsPublisher

java.lang.Object
com.team2813.lib2813.util.BuildConstantsPublisher

public final class BuildConstantsPublisher extends Object
Publishes build constants to NetworkTables.

The "build constants" are metadata related to the state of the code at the time it was built, e.g, git branch, git commit, build time, etc. This information can be very valuable when troubleshooting issues with the live code of the robot.

BuildConstantsPublisher receives this information from a specially built (as explained below) BuildConstants class at build time. It provides an interface to publish it to NetworkTables (publish(NetworkTableInstance)) or print it to the robot console (log()) - at runtime. Build constants need to be published only once, typically during robot initialization.

The constants are published under the "/Metadata" table in NetworkTables. This is a special NetworkTables table. Some tools have special support for the "/Metadata" table. For instance, Advantage Scope has a dedicated Metadata tab that loads information like Build Constants in a well formated table view.

To instantiate a BuildConstantsPublisher, a build constants class, BuildConstants, is needs to be generated for the robot library by enabling the `gversion` plugin in the gradle build file. Instructions can be found in the WPILib documentation.

With the BuildConstants generation enabled, the publisher is initialized and used like this:


 BuildConstantsPublisher buildConstantsPublisher(frc.robot.BuildConstants.class);
 // Publish the build constants to "/Metadata" on the NetworkTables
 buildConstantsPublisher.publish(NetworkTableInstance.getDefault());
 // Log the build constants in the robot console as well.
 buildConstantsPublisher.log();
 
Since:
2.0.0
  • Field Details

    • METADATA_TABLE_NAME

      public static final String METADATA_TABLE_NAME
      The name of the NetworkTable under which the build constants are published.
      See Also:
  • Constructor Details

    • BuildConstantsPublisher

      public BuildConstantsPublisher(Class<?> buildConstantsClass)
      Constructs a BuildConstantsPublisher.

      This constructor creates publishers for each build constant and publishes them to the provided network table instance.

      Parameters:
      buildConstantsClass - Specially built class that contains the robot code built-time constants. See class description for instructions on how to generate the class.
  • Method Details

    • buildConstants

      public Optional<BuildConstants> buildConstants()
      Gets the build constants extracted from the publisher.
    • publish

      public void publish(NetworkTableInstance ntInstance)
      Publishes the build constants to NetworkTables.

      This is typically called once during robot initialization.

      Parameters:
      ntInstance - The top-level NetworkTable instance under whose "/Metadata" table the build constants are published.
    • log

      public void log()
      Logs the build constants to the console.