Skip to content

Commit

Permalink
[hal] Add usage reporting ids from 2024v2 image (#6041)
Browse files Browse the repository at this point in the history
  • Loading branch information
guineawheek authored Dec 15, 2023
1 parent f87c64a commit 9599c1f
Show file tree
Hide file tree
Showing 6 changed files with 251 additions and 39 deletions.
72 changes: 35 additions & 37 deletions hal/generate_usage_reporting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,48 @@
# 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 os
import pathlib


def main():
# Gets the folder this script is in (the hal/ directory)
HAL_ROOT = pathlib.Path(__file__).parent
java_package = "edu/wpi/first/hal"
os.makedirs("hal/src/generated/main/native/include/hal", exist_ok=True)
os.makedirs(f"hal/src/generated/main/java/{java_package}", exist_ok=True)
usage_reporting_types_cpp = ""
usage_reporting_instances_cpp = ""
usage_reporting_types = ""
usage_reporting_instances = ""
with open("hal/src/generate/Instances.txt") as instances:
(HAL_ROOT/"src/generated/main/native/include/hal").mkdir(parents=True, exist_ok=True)
(HAL_ROOT/f"src/generated/main/java/{java_package}").mkdir(parents=True, exist_ok=True)
usage_reporting_types_cpp = []
usage_reporting_instances_cpp = []
usage_reporting_types = []
usage_reporting_instances = []
with open(HAL_ROOT/"src/generate/Instances.txt") as instances:
for instance in instances:
usage_reporting_instances_cpp = f"{usage_reporting_instances_cpp}\n {instance.strip()},"
usage_reporting_instances = f"{usage_reporting_instances}\n public static final int {instance.strip()};"
usage_reporting_instances_cpp.append(f" {instance.strip()},")
usage_reporting_instances.append(
f" /** {instance.strip()}. */\n"
f" public static final int {instance.strip()};")

with open("hal/src/generate/ResourceType.txt") as resource_types:
with open(HAL_ROOT/"src/generate/ResourceType.txt") as resource_types:
for resource_type in resource_types:
usage_reporting_types_cpp = f"{usage_reporting_types_cpp}\n {resource_type.strip()},"
usage_reporting_types = f"{usage_reporting_types}\n public static final int {resource_type.strip()};"

with open("hal/src/generate/FRCNetComm.java.in") as java_usage_reporting:
contents = java_usage_reporting.read()
contents = contents.replace(
r"${usage_reporting_types}", usage_reporting_types)
if os.path.exists(f"hal/src/generated/main/java/{java_package}/FRCNetComm.java"):
with open(f"hal/src/generated/main/java/{java_package}/FRCNetComm.java", "w") as java_out:
java_out.write(contents.replace(
r"${usage_reporting_instances}", usage_reporting_instances))
else:
with open(f"hal/src/generated/main/java/{java_package}/FRCNetComm.java", "x") as java_out:
java_out.write(contents.replace(
r"${usage_reporting_instances}", usage_reporting_instances))

with open("hal/src/generate/FRCUsageReporting.h.in") as cpp_usage_reporting:
contents = cpp_usage_reporting.read()
contents = contents.replace(r"${usage_reporting_types_cpp}", usage_reporting_types_cpp).replace(
r"${usage_reporting_instances_cpp}", usage_reporting_instances_cpp)
if os.path.exists("hal/src/generated/main/native/include/hal/FRCUsageReporting.h"):
with open("hal/src/generated/main/native/include/hal/FRCUsageReporting.h", "w") as cpp_out:
cpp_out.write(contents)
else:
with open("hal/src/generated/main/native/include/hal/FRCUsageReporting.h", "x") as cpp_out:
cpp_out.write(contents)
usage_reporting_types_cpp.append(f" {resource_type.strip()},")
usage_reporting_types.append(
f" /** {resource_type.strip()}. */\n"
f" public static final int {resource_type.strip()};")

with open(HAL_ROOT/"src/generate/FRCNetComm.java.in") as java_usage_reporting:
contents = (java_usage_reporting.read()
.replace(r"${usage_reporting_types}", "\n".join(usage_reporting_types))
.replace(r"${usage_reporting_instances}", "\n".join(usage_reporting_instances)))

with open(HAL_ROOT/f"src/generated/main/java/{java_package}/FRCNetComm.java", "w") as java_out:
java_out.write(contents)

with open(HAL_ROOT/"src/generate/FRCUsageReporting.h.in") as cpp_usage_reporting:
contents = (cpp_usage_reporting.read()
.replace(r"${usage_reporting_types_cpp}", "\n".join(usage_reporting_types_cpp))
.replace(r"${usage_reporting_instances_cpp}", "\n".join(usage_reporting_instances_cpp)))

with open(HAL_ROOT/"src/generated/main/native/include/hal/FRCUsageReporting.h", "w") as cpp_out:
cpp_out.write(contents)


if __name__ == "__main__":
Expand Down
2 changes: 2 additions & 0 deletions hal/src/generate/FRCNetComm.java.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class FRCNetComm {
public static final class tResourceType {
private tResourceType() {
}

${usage_reporting_types}
}

Expand All @@ -27,6 +28,7 @@ ${usage_reporting_types}
public static final class tInstances {
private tInstances() {
}

${usage_reporting_instances}
}
}
1 change: 1 addition & 0 deletions hal/src/generate/Instances.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ kFramework_CommandControl = 3
kFramework_Timed = 4
kFramework_ROS = 5
kFramework_RobotBuilder = 6
kFramework_AdvantageKit = 7
kRobotDrive_ArcadeStandard = 1
kRobotDrive_ArcadeButtonSpin = 2
kRobotDrive_ArcadeRatioCurve = 3
Expand Down
14 changes: 14 additions & 0 deletions hal/src/generate/ResourceType.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,17 @@ kResourceType_CTRE_future11 = 98
kResourceType_CTRE_future12 = 99
kResourceType_CTRE_future13 = 100
kResourceType_CTRE_future14 = 101
kResourceType_ExponentialProfile = 102
kResourceType_PS4Controller = 103
kResourceType_PhotonCamera = 104
kResourceType_PhotonPoseEstimator = 105
kResourceType_PathPlannerPath = 106
kResourceType_PathPlannerAuto = 107
kResourceType_PathFindingCommand = 108
kResourceType_Redux_future1 = 109
kResourceType_Redux_future2 = 110
kResourceType_Redux_future3 = 111
kResourceType_Redux_future4 = 112
kResourceType_Redux_future5 = 113
kResourceType_RevSparkFlexCAN = 114
kResourceType_RevSparkFlexPWM = 115
Loading

0 comments on commit 9599c1f

Please sign in to comment.