Package org.turbojax

Class TurboLogger

java.lang.Object
org.turbojax.TurboLogger

public class TurboLogger extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addAlias(String ntPath, String alias)
    Creates an alias for a key.
    static void
    Closes the existing DataLog file and resets it to null.
    static void
    Enables DataLog recording of NT output.
    static boolean
    get(String key, boolean defaultValue)
    Gets a boolean from NetworkTables.
    static boolean[]
    get(String key, boolean[] defaultValue)
    Gets a boolean array from NetworkTables.
    static double
    get(String key, double defaultValue)
    Gets a double from NetworkTables.
    static double[]
    get(String key, double[] defaultValue)
    Gets a double array from NetworkTables.
    static float
    get(String key, float defaultValue)
    Gets a float from NetworkTables.
    static float[]
    get(String key, float[] defaultValue)
    Gets a float array from NetworkTables.
    static int
    get(String key, int defaultValue)
    Gets an int from NetworkTables.
    static int[]
    get(String key, int[] defaultValue)
    Gets an int array from NetworkTables.
    static String
    get(String key, String defaultValue)
    Gets a string from NetworkTables.
    static String[]
    get(String key, String[] defaultValue)
    Gets a string array from NetworkTables.
    static <T extends StructSerializable>
    T
    get(String key, T defaultValue)
    Gets a struct serialized object from NetworkTables.
    static <T extends StructSerializable>
    T[]
    get(String key, T[] defaultValue)
    Gets an array of struct serialized objects from NetworkTables.
    static boolean
    Gets whether or not the logged value has changed since the last time the key was read from.
    static void
    log(String key, boolean value)
    Logs a boolean to NetworkTables.
    static void
    log(String key, boolean[] value)
    Logs a boolean array to NetworkTables.
    static void
    log(String key, double value)
    Logs a double to NetworkTables.
    static void
    log(String key, double[] value)
    Logs a double array to NetworkTables.
    static void
    log(String key, float value)
    Logs a float to NetworkTables.
    static void
    log(String key, float[] value)
    Logs a float array to NetworkTables.
    static void
    log(String key, int value)
    Logs an int to NetworkTables.
    static void
    log(String key, int[] value)
    Logs an int array to NetworkTables.
    static void
    log(String key, String value)
    Logs a string to NetworkTables.
    static void
    log(String key, String[] value)
    Logs a string array to NetworkTables.
    static <T extends StructSerializable>
    void
    log(String key, T value)
    Logs a struct to NetworkTables.
    static <T extends StructSerializable>
    void
    log(String key, T[] value)
    Logs a struct array to NetworkTables.
    static void
    Removes a key from the logger.
    static void
    Removes an alias.

    Methods inherited from class java.lang.Object

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

    • TurboLogger

      public TurboLogger()
  • Method Details

    • enableDataLogs

      public static void enableDataLogs(String logPath)
      Enables DataLog recording of NT output.

      The wpilog is created at the logPath point. If the logPath ends with a forward slash, it is seen as a directory. Otherwise, it is seen as a file.

      Parameters:
      logPath - The path to store the logfile at.
    • disableDataLogs

      public static void disableDataLogs()
      Closes the existing DataLog file and resets it to null.
    • log

      public static void log(String key, boolean[] value)
      Logs a boolean array to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The boolean array to log.
    • log

      public static void log(String key, boolean value)
      Logs a boolean to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The boolean to log.
    • log

      public static void log(String key, double[] value)
      Logs a double array to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The double array to log.
    • log

      public static void log(String key, double value)
      Logs a double to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The double to log.
    • log

      public static void log(String key, float[] value)
      Logs a float array to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The float array to log.
    • log

      public static void log(String key, float value)
      Logs a float to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The float to log.
    • log

      public static void log(String key, int[] value)
      Logs an int array to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The int array to log.
    • log

      public static void log(String key, int value)
      Logs an int to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The int to log.
    • log

      public static void log(String key, String[] value)
      Logs a string array to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The string array to log.
    • log

      public static void log(String key, String value)
      Logs a string to NetworkTables.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The string to log.
    • log

      public static <T extends StructSerializable> void log(String key, T[] value)
      Logs a struct array to NetworkTables.
      Type Parameters:
      T - An object to log that implements StructSerializable.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The struct array to log.
    • log

      public static <T extends StructSerializable> void log(String key, T value)
      Logs a struct to NetworkTables.
      Type Parameters:
      T - An object to log that implements StructSerializable.
      Parameters:
      key - The key to log the value under. This can be a NetworkTables path or an alias.
      value - The struct to log.
    • get

      public static boolean[] get(String key, boolean[] defaultValue)
      Gets a boolean array from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The boolean array referenced by the key
    • get

      public static boolean get(String key, boolean defaultValue)
      Gets a boolean from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The boolean referenced by the key.
    • get

      public static double[] get(String key, double[] defaultValue)
      Gets a double array from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The double array referenced by the key.
    • get

      public static double get(String key, double defaultValue)
      Gets a double from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The double referenced by the key.
    • get

      public static float[] get(String key, float[] defaultValue)
      Gets a float array from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The float array referenced by the key.
    • get

      public static float get(String key, float defaultValue)
      Gets a float from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The float referenced by the key.
    • get

      public static int[] get(String key, int[] defaultValue)
      Gets an int array from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The integer array referenced by the key.
    • get

      public static int get(String key, int defaultValue)
      Gets an int from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The int referenced by the key.
    • get

      public static String[] get(String key, String[] defaultValue)
      Gets a string array from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The string array referenced by the key.
    • get

      public static String get(String key, String defaultValue)
      Gets a string from NetworkTables.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The string referenced by the key.
    • get

      public static <T extends StructSerializable> T[] get(String key, T[] defaultValue)
      Gets an array of struct serialized objects from NetworkTables.
      Type Parameters:
      T - An object to log that implements StructSerializable.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The array of StructSerializable objects referenced by the key.
    • get

      public static <T extends StructSerializable> T get(String key, T defaultValue)
      Gets a struct serialized object from NetworkTables.
      Type Parameters:
      T - An object to log that implements StructSerializable.
      Parameters:
      key - The key to find the value under.
      defaultValue - The value to return if the subscriber doesn't exist.
      Returns:
      The struct serialized object referenced by the key.
    • hasChanged

      public static boolean hasChanged(String key)
      Gets whether or not the logged value has changed since the last time the key was read from.
      Parameters:
      key - The key to check the status of. This can be the path in NetworkTables or an alias.
      Returns:
      Whether or not the logged value has changed.
    • remove

      public static void remove(String key)
      Removes a key from the logger.

      If the key is an alias, it removes the parent NetworkTables path and all other aliases.

      Parameters:
      key - The key to remove. It can be an alias or a NetworkTables path.
    • addAlias

      public static void addAlias(String ntPath, String alias)
      Creates an alias for a key. Aliases are accepted as alternatives for the key in the TurboLogger.log or TurboLogger.get methods. They can also increase readability in the code.

      Aliases have their own entry in the lastRead table. This means that when you get an alias, it does not mark the main key or any other aliases for that key as read.

      Parameters:
      ntPath - The path to create an alias for.
      alias - The alias to add.
    • removeAlias

      public static void removeAlias(String alias)
      Removes an alias.

      This does not remove the parent key or affect any of the other other aliases associated with that key.

      Parameters:
      alias - The alias to remove.