From 44c1538a5da76327a67c97978ae33a1839f243b8 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Fri, 16 Aug 2024 22:28:01 +0800 Subject: [PATCH] [wpiutil] DataLog: Use codegen for entry types Signed-off-by: Jade Turner --- .github/workflows/pregen_all.py | 4 + wpiutil/BUILD.bazel | 5 +- wpiutil/CMakeLists.txt | 2 +- wpiutil/build.gradle | 2 + wpiutil/generate_datalog_entries.py | 66 ++++++ wpiutil/src/main/generate/LogEntry.java.jinja | 217 ++++++++++++++++++ wpiutil/src/main/generate/types.json | 64 ++++++ .../util/datalog/BooleanArrayLogEntry.java | 23 +- .../first/util/datalog/BooleanLogEntry.java | 7 + .../util/datalog/DoubleArrayLogEntry.java | 21 +- .../first/util/datalog/DoubleLogEntry.java | 13 +- .../util/datalog/FloatArrayLogEntry.java | 21 +- .../wpi/first/util/datalog/FloatLogEntry.java | 13 +- .../util/datalog/IntegerArrayLogEntry.java | 21 +- .../first/util/datalog/IntegerLogEntry.java | 25 +- .../util/datalog/StringArrayLogEntry.java | 21 +- .../first/util/datalog/StringLogEntry.java | 46 ++-- 17 files changed, 487 insertions(+), 84 deletions(-) create mode 100755 wpiutil/generate_datalog_entries.py create mode 100644 wpiutil/src/main/generate/LogEntry.java.jinja create mode 100644 wpiutil/src/main/generate/types.json rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java (91%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/BooleanLogEntry.java (97%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java (92%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/DoubleLogEntry.java (94%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java (92%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/FloatLogEntry.java (94%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java (92%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/IntegerLogEntry.java (88%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java (92%) rename wpiutil/src/main/{ => generated}/java/edu/wpi/first/util/datalog/StringLogEntry.java (76%) diff --git a/.github/workflows/pregen_all.py b/.github/workflows/pregen_all.py index 278e5c84cd8..a2eef1e62d7 100755 --- a/.github/workflows/pregen_all.py +++ b/.github/workflows/pregen_all.py @@ -71,6 +71,10 @@ def main(): [sys.executable, f"{REPO_ROOT}/thirdparty/imgui_suite/generate_gl3w.py"], check=True, ) + subprocess.run( + [sys.executable, f"{REPO_ROOT}/wpiutil/generate_datalog_entries.py"], + check=True, + ) subprocess.run(f"{REPO_ROOT}/thirdparty/imgui_suite/generate_fonts.sh", check=True) diff --git a/wpiutil/BUILD.bazel b/wpiutil/BUILD.bazel index 6e9318bedff..2757d9b7e83 100644 --- a/wpiutil/BUILD.bazel +++ b/wpiutil/BUILD.bazel @@ -226,7 +226,10 @@ cc_library( java_library( name = "wpiutil-java", - srcs = glob(["src/main/java/**/*.java"]), + srcs = glob([ + "src/main/java/**/*.java", + "src/generated/java/**/*.java", + ]), visibility = ["//visibility:public"], deps = [ "@maven//:com_fasterxml_jackson_core_jackson_annotations", diff --git a/wpiutil/CMakeLists.txt b/wpiutil/CMakeLists.txt index 62d517495da..ba83fbdffae 100644 --- a/wpiutil/CMakeLists.txt +++ b/wpiutil/CMakeLists.txt @@ -57,7 +57,7 @@ if(WITH_JAVA) set(CMAKE_JNI_TARGET true) - file(GLOB_RECURSE JAVA_SOURCES src/main/java/*.java) + file(GLOB_RECURSE JAVA_SOURCES src/main/*.java) add_jar( wpiutil_jar diff --git a/wpiutil/build.gradle b/wpiutil/build.gradle index 5191e17e56e..d17d96992ed 100644 --- a/wpiutil/build.gradle +++ b/wpiutil/build.gradle @@ -298,6 +298,8 @@ model { } } +sourceSets.main.java.srcDir "${projectDir}/src/main/generated/java" + sourceSets { printlog } diff --git a/wpiutil/generate_datalog_entries.py b/wpiutil/generate_datalog_entries.py new file mode 100755 index 00000000000..da77959acec --- /dev/null +++ b/wpiutil/generate_datalog_entries.py @@ -0,0 +1,66 @@ +#!/usr/bin/env python3 + +# Copyright (c) FIRST and other WPILib contributors. +# Open Source Software; you can modify and/or share it under the terms of +# the WPILib BSD license file in the root directory of this project. +import argparse +import json +import sys +from pathlib import Path +from typing import Any, Dict + +from jinja2 import Environment, FileSystemLoader +from jinja2.environment import Template + + +def render_template( + template: Template, output_dir: Path, filename: str, ty: Dict[str, Any] +): + output_dir.mkdir(parents=True, exist_ok=True) + + output_file = output_dir / filename + output_file.write_text(template.render(ty), encoding="utf-8") + + +def generate_log_entries(output_root, template_root): + with (template_root / "types.json").open(encoding="utf-8") as f: + types = json.load(f)["types"] + + env = Environment( + loader=FileSystemLoader(str(template_root)), + autoescape=False, + keep_trailing_newline=True, + ) + + java_root_path = Path(output_root) / "java/edu/wpi/first/util/datalog" + java_template = env.get_template("LogEntry.java.jinja") + + for ty in types: + entry_name = f"{ty['name']}LogEntry.java" + render_template(java_template, java_root_path, entry_name, ty) + + +def main(argv): + script_path = Path(__file__).resolve() + dirname = script_path.parent + + parser = argparse.ArgumentParser() + parser.add_argument( + "--output_directory", + help="Optional. If set, will output the generated files to this directory, otherwise it will use a path relative to the script", + default=dirname / "src/main/generated", + type=Path, + ) + parser.add_argument( + "--template_root", + help="Optional. If set, will use this directory as the root for the jinja templates", + default=dirname / "src/main/generate", + type=Path, + ) + args = parser.parse_args(argv) + + generate_log_entries(args.output_directory, args.template_root) + + +if __name__ == "__main__": + main(sys.argv[1:]) diff --git a/wpiutil/src/main/generate/LogEntry.java.jinja b/wpiutil/src/main/generate/LogEntry.java.jinja new file mode 100644 index 00000000000..9ae8bab29fe --- /dev/null +++ b/wpiutil/src/main/generate/LogEntry.java.jinja @@ -0,0 +1,217 @@ +// Copyright (c) FIRST and other WPILib contributors. +// Open Source Software; you can modify and/or share it under the terms of +// the WPILib BSD license file in the root directory of this project. + +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + +package edu.wpi.first.util.datalog; + +{% if IsArray %} +import java.util.Arrays; +{% endif %} + +/** Log {{ DataType }} values. */ +public class {{ name }}LogEntry extends DataLogEntry { + /** The data type for {{ DataType }} values. */ + public static final String kDataType = "{{ DataType }}"; + + /** + * Constructs a {{ DataType }} log entry. + * + * @param log datalog + * @param name name of the entry + * @param metadata metadata + * @param timestamp entry creation timestamp (0=now) + */ + public {{ name }}LogEntry(DataLog log, String name, String metadata, long timestamp) { + super(log, name, kDataType, metadata, timestamp); + } + + /** + * Constructs a {{ DataType }} log entry. + * + * @param log datalog + * @param name name of the entry + * @param metadata metadata + */ + public {{ name }}LogEntry(DataLog log, String name, String metadata) { + this(log, name, metadata, 0); + } + + /** + * Constructs a {{ DataType }} log entry. + * + * @param log datalog + * @param name name of the entry + * @param timestamp entry creation timestamp (0=now) + */ + public {{ name }}LogEntry(DataLog log, String name, long timestamp) { + this(log, name, "", timestamp); + } + + /** + * Constructs a {{ DataType }} log entry. + * + * @param log datalog + * @param name name of the entry + */ + public {{ name }}LogEntry(DataLog log, String name) { + this(log, name, 0); + } + + /** + * Appends a record to the log. + * + * @param value Value to record + * @param timestamp Time stamp (0 to indicate now) + */ + public void append({{ AppendType }} value, long timestamp) { + m_log.append{{ name }}(m_entry, value, timestamp); + } + + /** + * Appends a record to the log. + * + * @param value Value to record + */ + public void append({{ AppendType }} value) { + m_log.append{{ name }}(m_entry, value, 0); + } + +{% if IsArray %} + /** + * Updates the last value and appends a record to the log if it has changed. + * + *

Note: the last value is local to this class instance; using update() with two instances + * pointing to the same underlying log entry name will likely result in unexpected results. + * + * @param value Value to record + * @param timestamp Time stamp (0 to indicate now) + */ + public synchronized void update({{ AppendType }} value, long timestamp) { + if (!equalsLast(value)) { + copyToLast(value); + append(value, timestamp); + } + } + + /** + * Updates the last value and appends a record to the log if it has changed. + * + *

Note: the last value is local to this class instance; using update() with two instances + * pointing to the same underlying log entry name will likely result in unexpected results. + * + * @param value Value to record + */ + public void update({{ AppendType }} value) { + update(value, 0); + } + + /** + * Gets whether there is a last value. + * + *

Note: the last value is local to this class instance and updated only with update(), not + * append(). + * + * @return True if last value exists, false otherwise. + */ + public synchronized boolean hasLastValue() { + return m_lastValue != null; + } + + /** + * Gets the last value. + * + *

Note: the last value is local to this class instance and updated only with update(), not + * append(). + * + * @return Last value, or false if none. + */ + @SuppressWarnings("PMD.ReturnEmptyCollectionRatherThanNull") + public synchronized {{ AppendType }} getLastValue() { + if (m_lastValue == null) { + return null; + } + return Arrays.copyOf(m_lastValue, m_lastValueLen); + } + + private boolean equalsLast({{ AppendType }} value) { + if (m_lastValue == null || m_lastValueLen != value.length) { + return false; + } + return Arrays.equals(m_lastValue, 0, value.length, value, 0, value.length); + } + + private void copyToLast({{ AppendType }} value) { + if (m_lastValue == null || m_lastValue.length < value.length) { + m_lastValue = Arrays.copyOf(value, value.length); + } else { + System.arraycopy(value, 0, m_lastValue, 0, value.length); + } + m_lastValueLen = value.length; + } + + private int m_lastValueLen; +{% else %} + /** + * Updates the last value and appends a record to the log if it has changed. + * + *

Note: the last value is local to this class instance; using update() with two instances + * pointing to the same underlying log entry name will likely result in unexpected results. + * + * @param value Value to record + * @param timestamp Time stamp (0 to indicate now) + */ + public synchronized void update({{ AppendType }} value, long timestamp) { +{%- if AppendType == "String" %} + if (!m_hasLastValue || !m_lastValue.equals(value)) { +{%- else %} + if (!m_hasLastValue || m_lastValue != value) { +{%- endif %} + m_lastValue = value; + m_hasLastValue = true; + append(value, timestamp); + } + } + + /** + * Updates the last value and appends a record to the log if it has changed. + * + *

Note: the last value is local to this class instance; using update() with two instances + * pointing to the same underlying log entry name will likely result in unexpected results. + * + * @param value Value to record + */ + public void update({{ AppendType }} value) { + update(value, 0); + } + + /** + * Gets whether there is a last value. + * + *

Note: the last value is local to this class instance and updated only with update(), not + * append(). + * + * @return True if last value exists, false otherwise. + */ + public synchronized boolean hasLastValue() { + return m_hasLastValue; + } + + /** + * Gets the last value. + * + *

Note: the last value is local to this class instance and updated only with update(), not + * append(). + * + * @return Last value, or false if none. + */ + public synchronized {{ AppendType }} getLastValue() { + return m_lastValue; + } + + private boolean m_hasLastValue; +{% endif %} + + private {{ AppendType }} m_lastValue; +} diff --git a/wpiutil/src/main/generate/types.json b/wpiutil/src/main/generate/types.json new file mode 100644 index 00000000000..245dc418b1b --- /dev/null +++ b/wpiutil/src/main/generate/types.json @@ -0,0 +1,64 @@ +{ + "types": [ + { + "name": "Double", + "DataType": "double", + "AppendType": "double", + "IsArray": false + }, + { + "name": "DoubleArray", + "DataType": "double[]", + "AppendType": "double[]", + "IsArray": true + }, + { + "name": "Float", + "DataType": "float", + "AppendType": "float", + "IsArray": false + }, + { + "name": "FloatArray", + "DataType": "float[]", + "AppendType": "float[]", + "IsArray": true + }, + { + "name": "Integer", + "DataType": "int64", + "AppendType": "long", + "IsArray": false + }, + { + "name": "IntegerArray", + "DataType": "int64[]", + "AppendType": "long[]", + "IsArray": true + }, + { + "name": "Boolean", + "DataType": "boolean", + "AppendType": "boolean", + "IsArray": false + }, + { + "name": "BooleanArray", + "DataType": "boolean[]", + "AppendType": "boolean[]", + "IsArray": true + }, + { + "name": "String", + "DataType": "String", + "AppendType": "String", + "IsArray": false + }, + { + "name": "StringArray", + "DataType": "string[]", + "AppendType": "String[]", + "IsArray": true + } + ] +} diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java similarity index 91% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java index 76b85f518c2..ef11ca482c3 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/BooleanArrayLogEntry.java @@ -2,17 +2,21 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + import java.util.Arrays; -/** Log array of boolean values. */ + +/** Log boolean[] values. */ public class BooleanArrayLogEntry extends DataLogEntry { - /** The data type for boolean array values. */ + /** The data type for boolean[] values. */ public static final String kDataType = "boolean[]"; /** - * Constructs a boolean array log entry. + * Constructs a boolean[] log entry. * * @param log datalog * @param name name of the entry @@ -24,7 +28,7 @@ public BooleanArrayLogEntry(DataLog log, String name, String metadata, long time } /** - * Constructs a boolean array log entry. + * Constructs a boolean[] log entry. * * @param log datalog * @param name name of the entry @@ -35,7 +39,7 @@ public BooleanArrayLogEntry(DataLog log, String name, String metadata) { } /** - * Constructs a boolean array log entry. + * Constructs a boolean[] log entry. * * @param log datalog * @param name name of the entry @@ -46,7 +50,7 @@ public BooleanArrayLogEntry(DataLog log, String name, long timestamp) { } /** - * Constructs a boolean array log entry. + * Constructs a boolean[] log entry. * * @param log datalog * @param name name of the entry @@ -74,6 +78,7 @@ public void append(boolean[] value) { m_log.appendBooleanArray(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -120,7 +125,7 @@ public synchronized boolean hasLastValue() { *

Note: the last value is local to this class instance and updated only with update(), not * append(). * - * @return Last value, or null if none. + * @return Last value, or false if none. */ @SuppressWarnings("PMD.ReturnEmptyCollectionRatherThanNull") public synchronized boolean[] getLastValue() { @@ -146,6 +151,8 @@ private void copyToLast(boolean[] value) { m_lastValueLen = value.length; } - private boolean[] m_lastValue; private int m_lastValueLen; + + + private boolean[] m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/BooleanLogEntry.java similarity index 97% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/BooleanLogEntry.java index ba1783e1618..77abe41c4f0 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/BooleanLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/BooleanLogEntry.java @@ -2,8 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + + /** Log boolean values. */ public class BooleanLogEntry extends DataLogEntry { /** The data type for boolean values. */ @@ -72,6 +76,7 @@ public void append(boolean value) { m_log.appendBoolean(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -126,5 +131,7 @@ public synchronized boolean getLastValue() { } private boolean m_hasLastValue; + + private boolean m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java similarity index 92% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java index 2fe528f1bd3..fc3d37f8c1c 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/DoubleArrayLogEntry.java @@ -2,17 +2,21 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + import java.util.Arrays; -/** Log array of double values. */ + +/** Log double[] values. */ public class DoubleArrayLogEntry extends DataLogEntry { - /** The data type for double array values. */ + /** The data type for double[] values. */ public static final String kDataType = "double[]"; /** - * Constructs a double array log entry. + * Constructs a double[] log entry. * * @param log datalog * @param name name of the entry @@ -24,7 +28,7 @@ public DoubleArrayLogEntry(DataLog log, String name, String metadata, long times } /** - * Constructs a double array log entry. + * Constructs a double[] log entry. * * @param log datalog * @param name name of the entry @@ -35,7 +39,7 @@ public DoubleArrayLogEntry(DataLog log, String name, String metadata) { } /** - * Constructs a double array log entry. + * Constructs a double[] log entry. * * @param log datalog * @param name name of the entry @@ -46,7 +50,7 @@ public DoubleArrayLogEntry(DataLog log, String name, long timestamp) { } /** - * Constructs a double array log entry. + * Constructs a double[] log entry. * * @param log datalog * @param name name of the entry @@ -74,6 +78,7 @@ public void append(double[] value) { m_log.appendDoubleArray(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -146,6 +151,8 @@ private void copyToLast(double[] value) { m_lastValueLen = value.length; } - private double[] m_lastValue; private int m_lastValueLen; + + + private double[] m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/DoubleLogEntry.java similarity index 94% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/DoubleLogEntry.java index 2484063aba0..aa3b4337f1b 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/DoubleLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/DoubleLogEntry.java @@ -2,8 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + + /** Log double values. */ public class DoubleLogEntry extends DataLogEntry { /** The data type for double values. */ @@ -72,6 +76,7 @@ public void append(double value) { m_log.appendDouble(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -119,12 +124,14 @@ public synchronized boolean hasLastValue() { *

Note: the last value is local to this class instance and updated only with update(), not * append(). * - * @return Last value, or 0 if none. + * @return Last value, or false if none. */ public synchronized double getLastValue() { return m_lastValue; } - boolean m_hasLastValue; - double m_lastValue; + private boolean m_hasLastValue; + + + private double m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java similarity index 92% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java index 136b7e5b420..a24cd24a6f5 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/FloatArrayLogEntry.java @@ -2,17 +2,21 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + import java.util.Arrays; -/** Log array of float values. */ + +/** Log float[] values. */ public class FloatArrayLogEntry extends DataLogEntry { - /** The data type for float array values. */ + /** The data type for float[] values. */ public static final String kDataType = "float[]"; /** - * Constructs a float array log entry. + * Constructs a float[] log entry. * * @param log datalog * @param name name of the entry @@ -24,7 +28,7 @@ public FloatArrayLogEntry(DataLog log, String name, String metadata, long timest } /** - * Constructs a float array log entry. + * Constructs a float[] log entry. * * @param log datalog * @param name name of the entry @@ -35,7 +39,7 @@ public FloatArrayLogEntry(DataLog log, String name, String metadata) { } /** - * Constructs a float array log entry. + * Constructs a float[] log entry. * * @param log datalog * @param name name of the entry @@ -46,7 +50,7 @@ public FloatArrayLogEntry(DataLog log, String name, long timestamp) { } /** - * Constructs a float array log entry. + * Constructs a float[] log entry. * * @param log datalog * @param name name of the entry @@ -74,6 +78,7 @@ public void append(float[] value) { m_log.appendFloatArray(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -146,6 +151,8 @@ private void copyToLast(float[] value) { m_lastValueLen = value.length; } - private float[] m_lastValue; private int m_lastValueLen; + + + private float[] m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/FloatLogEntry.java similarity index 94% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/FloatLogEntry.java index 8cb02cfafdd..8e6066201cc 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/FloatLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/FloatLogEntry.java @@ -2,8 +2,12 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + + /** Log float values. */ public class FloatLogEntry extends DataLogEntry { /** The data type for float values. */ @@ -72,6 +76,7 @@ public void append(float value) { m_log.appendFloat(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -119,12 +124,14 @@ public synchronized boolean hasLastValue() { *

Note: the last value is local to this class instance and updated only with update(), not * append(). * - * @return Last value, or 0 if none. + * @return Last value, or false if none. */ public synchronized float getLastValue() { return m_lastValue; } - boolean m_hasLastValue; - float m_lastValue; + private boolean m_hasLastValue; + + + private float m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java similarity index 92% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java index 80e2be36d95..b63ad6056ab 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/IntegerArrayLogEntry.java @@ -2,17 +2,21 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + import java.util.Arrays; -/** Log array of integer values. */ + +/** Log int64[] values. */ public class IntegerArrayLogEntry extends DataLogEntry { - /** The data type for integer array values. */ + /** The data type for int64[] values. */ public static final String kDataType = "int64[]"; /** - * Constructs a integer array log entry. + * Constructs a int64[] log entry. * * @param log datalog * @param name name of the entry @@ -24,7 +28,7 @@ public IntegerArrayLogEntry(DataLog log, String name, String metadata, long time } /** - * Constructs a integer array log entry. + * Constructs a int64[] log entry. * * @param log datalog * @param name name of the entry @@ -35,7 +39,7 @@ public IntegerArrayLogEntry(DataLog log, String name, String metadata) { } /** - * Constructs a integer array log entry. + * Constructs a int64[] log entry. * * @param log datalog * @param name name of the entry @@ -46,7 +50,7 @@ public IntegerArrayLogEntry(DataLog log, String name, long timestamp) { } /** - * Constructs a integer array log entry. + * Constructs a int64[] log entry. * * @param log datalog * @param name name of the entry @@ -74,6 +78,7 @@ public void append(long[] value) { m_log.appendIntegerArray(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -146,6 +151,8 @@ private void copyToLast(long[] value) { m_lastValueLen = value.length; } - private long[] m_lastValue; private int m_lastValueLen; + + + private long[] m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/IntegerLogEntry.java similarity index 88% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/IntegerLogEntry.java index 25f491cc035..b94a87aae93 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/IntegerLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/IntegerLogEntry.java @@ -2,15 +2,19 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; -/** Log integer values. */ + + +/** Log int64 values. */ public class IntegerLogEntry extends DataLogEntry { - /** The data type for integer values. */ + /** The data type for int64 values. */ public static final String kDataType = "int64"; /** - * Constructs a integer log entry. + * Constructs a int64 log entry. * * @param log datalog * @param name name of the entry @@ -22,7 +26,7 @@ public IntegerLogEntry(DataLog log, String name, String metadata, long timestamp } /** - * Constructs a integer log entry. + * Constructs a int64 log entry. * * @param log datalog * @param name name of the entry @@ -33,7 +37,7 @@ public IntegerLogEntry(DataLog log, String name, String metadata) { } /** - * Constructs a integer log entry. + * Constructs a int64 log entry. * * @param log datalog * @param name name of the entry @@ -44,7 +48,7 @@ public IntegerLogEntry(DataLog log, String name, long timestamp) { } /** - * Constructs a integer log entry. + * Constructs a int64 log entry. * * @param log datalog * @param name name of the entry @@ -72,6 +76,7 @@ public void append(long value) { m_log.appendInteger(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -119,12 +124,14 @@ public synchronized boolean hasLastValue() { *

Note: the last value is local to this class instance and updated only with update(), not * append(). * - * @return Last value, or 0 if none. + * @return Last value, or false if none. */ public synchronized long getLastValue() { return m_lastValue; } - boolean m_hasLastValue; - long m_lastValue; + private boolean m_hasLastValue; + + + private long m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java similarity index 92% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java index 0218502fc04..819f6c14c99 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/StringArrayLogEntry.java @@ -2,17 +2,21 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; + import java.util.Arrays; -/** Log array of string values. */ + +/** Log string[] values. */ public class StringArrayLogEntry extends DataLogEntry { - /** The data type for string array values. */ + /** The data type for string[] values. */ public static final String kDataType = "string[]"; /** - * Constructs a string array log entry. + * Constructs a string[] log entry. * * @param log datalog * @param name name of the entry @@ -24,7 +28,7 @@ public StringArrayLogEntry(DataLog log, String name, String metadata, long times } /** - * Constructs a string array log entry. + * Constructs a string[] log entry. * * @param log datalog * @param name name of the entry @@ -35,7 +39,7 @@ public StringArrayLogEntry(DataLog log, String name, String metadata) { } /** - * Constructs a string array log entry. + * Constructs a string[] log entry. * * @param log datalog * @param name name of the entry @@ -46,7 +50,7 @@ public StringArrayLogEntry(DataLog log, String name, long timestamp) { } /** - * Constructs a string array log entry. + * Constructs a string[] log entry. * * @param log datalog * @param name name of the entry @@ -74,6 +78,7 @@ public void append(String[] value) { m_log.appendStringArray(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -146,6 +151,8 @@ private void copyToLast(String[] value) { m_lastValueLen = value.length; } - private String[] m_lastValue; private int m_lastValueLen; + + + private String[] m_lastValue; } diff --git a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/StringLogEntry.java similarity index 76% rename from wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java rename to wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/StringLogEntry.java index 523abd6646b..55aef2a99ca 100644 --- a/wpiutil/src/main/java/edu/wpi/first/util/datalog/StringLogEntry.java +++ b/wpiutil/src/main/generated/java/edu/wpi/first/util/datalog/StringLogEntry.java @@ -2,37 +2,16 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. +// THIS FILE WAS GENERATED BY generate_datalog_entries.py DO NOT EDIT IT MANUALLY + package edu.wpi.first.util.datalog; -/** Log string values. */ -public class StringLogEntry extends DataLogEntry { - /** The data type for string values. */ - public static final String kDataType = "string"; - /** - * Constructs a String log entry. - * - * @param log datalog - * @param name name of the entry - * @param metadata metadata - * @param type Data type - * @param timestamp entry creation timestamp (0=now) - */ - public StringLogEntry(DataLog log, String name, String metadata, String type, long timestamp) { - super(log, name, type, metadata, timestamp); - } - /** - * Constructs a String log entry. - * - * @param log datalog - * @param name name of the entry - * @param metadata metadata - * @param type Data type - */ - public StringLogEntry(DataLog log, String name, String metadata, String type) { - this(log, name, metadata, type, 0); - } +/** Log String values. */ +public class StringLogEntry extends DataLogEntry { + /** The data type for String values. */ + public static final String kDataType = "String"; /** * Constructs a String log entry. @@ -43,7 +22,7 @@ public StringLogEntry(DataLog log, String name, String metadata, String type) { * @param timestamp entry creation timestamp (0=now) */ public StringLogEntry(DataLog log, String name, String metadata, long timestamp) { - this(log, name, metadata, kDataType, timestamp); + super(log, name, kDataType, metadata, timestamp); } /** @@ -97,6 +76,7 @@ public void append(String value) { m_log.appendString(m_entry, value, 0); } + /** * Updates the last value and appends a record to the log if it has changed. * @@ -107,8 +87,9 @@ public void append(String value) { * @param timestamp Time stamp (0 to indicate now) */ public synchronized void update(String value, long timestamp) { - if (m_lastValue == null || !value.equals(m_lastValue)) { + if (!m_hasLastValue || !m_lastValue.equals(value)) { m_lastValue = value; + m_hasLastValue = true; append(value, timestamp); } } @@ -134,7 +115,7 @@ public void update(String value) { * @return True if last value exists, false otherwise. */ public synchronized boolean hasLastValue() { - return m_lastValue != null; + return m_hasLastValue; } /** @@ -143,11 +124,14 @@ public synchronized boolean hasLastValue() { *

Note: the last value is local to this class instance and updated only with update(), not * append(). * - * @return Last value, or null if none. + * @return Last value, or false if none. */ public synchronized String getLastValue() { return m_lastValue; } + private boolean m_hasLastValue; + + private String m_lastValue; }