From 806c26f9d889d115cb73237134af8a5a72543975 Mon Sep 17 00:00:00 2001 From: Jade Turner Date: Fri, 6 Dec 2024 20:56:10 +0800 Subject: [PATCH] [choreolib] Fix C++ version checking Resolves https://github.com/SleipnirGroup/Choreo/issues/973 Signed-off-by: Jade Turner --- choreolib/src/main/native/include/choreo/Choreo.h | 11 ++++++----- docs/contributing/schema-upgrade.md | 4 ++-- src/assets/Angle.tsx | 4 +++- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/choreolib/src/main/native/include/choreo/Choreo.h b/choreolib/src/main/native/include/choreo/Choreo.h index 11599fbcad..5f3fdaabb7 100644 --- a/choreolib/src/main/native/include/choreo/Choreo.h +++ b/choreolib/src/main/native/include/choreo/Choreo.h @@ -27,7 +27,8 @@ namespace choreo { -inline constexpr uint32_t kSpecVersion = 1; +inline constexpr uint32_t kTrajSpecVersion = 0; +inline constexpr uint32_t kChorSpecVersion = 1; /** * A class that handles loading choreo and caching choreo trajectories. @@ -74,9 +75,9 @@ class Choreo { wpi::json json = wpi::json::parse(fileBuffer.value()->GetCharBuffer()); uint32_t version = json["version"]; - if (kSpecVersion != version) { + if (kChorSpecVersion != version) { throw fmt::format(".chor project file: Wrong version {}. Expected {}", - version, kSpecVersion); + version, kChorSpecVersion); } ProjectFile resultProjectFile; from_json(json, resultProjectFile); @@ -152,9 +153,9 @@ class Choreo { wpi::json json = wpi::json::parse(trajectoryJsonString); uint32_t version = json["version"]; - if (version != kSpecVersion) { + if (version != kTrajSpecVersion) { throw fmt::format("{}.traj: Wrong version {}. Expected {}", - trajectoryName, version, kSpecVersion); + trajectoryName, version, kTrajSpecVersion); } Trajectory trajectory; from_json(json, trajectory); diff --git a/docs/contributing/schema-upgrade.md b/docs/contributing/schema-upgrade.md index 8ac0e5bb5a..f9fea07c7c 100644 --- a/docs/contributing/schema-upgrade.md +++ b/docs/contributing/schema-upgrade.md @@ -100,11 +100,11 @@ Each store has a `get serialize()` computed property. This needs to be updated t #### `deserialize()` Each store has a `deserialize()` which populates the Mobx store from a data object. -## choreolib +## Choreolib Update TRAJ_SCHEMA_VERSION and PROJECT_SCHEMA_VERSION in the following: * Python: `choreolib/py/choreo/__init__.py` * Java: `choreolib/src/main/java/choreo/Choreo.java` -* C++ currently does not do version validation. +* C++: `choreolib/src/main/native/include/choreo/Choreo.h` Make any functional changes to the trajectory classes and loading methods in all three languages, according to the schema change being made. diff --git a/src/assets/Angle.tsx b/src/assets/Angle.tsx index 225cb67a05..328262e7cd 100644 --- a/src/assets/Angle.tsx +++ b/src/assets/Angle.tsx @@ -34,7 +34,9 @@ const Angle: React.FunctionComponent = (props) => { y2={cornerY - length * Math.sin(angle)} > );