Add y2023_bot3 folder
Signed-off-by: James (Peilun) Li <jamespeilunli@gmail.com>
Change-Id: I6fae2492d0497596a632efc79a6a258c0ca15f49
diff --git a/y2023_bot3/constants/8971.json b/y2023_bot3/constants/8971.json
new file mode 100644
index 0000000..aea0c6f
--- /dev/null
+++ b/y2023_bot3/constants/8971.json
@@ -0,0 +1,5 @@
+{
+ "robot": {
+ },
+ {% include 'y2023_bot3/constants/common.json' %}
+}
diff --git a/y2023_bot3/constants/BUILD b/y2023_bot3/constants/BUILD
new file mode 100644
index 0000000..40d77be
--- /dev/null
+++ b/y2023_bot3/constants/BUILD
@@ -0,0 +1,65 @@
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
+load("//tools/build_rules:template.bzl", "jinja2_template")
+
+cc_library(
+ name = "simulated_constants_sender",
+ srcs = ["simulated_constants_sender.cc"],
+ hdrs = ["simulated_constants_sender.h"],
+ data = [":test_constants.json"],
+ visibility = ["//y2023_bot3:__subpackages__"],
+ deps = [
+ ":constants_fbs",
+ ":constants_list_fbs",
+ "//aos/events:simulated_event_loop",
+ "//aos/testing:path",
+ "//frc971/constants:constants_sender_lib",
+ ],
+)
+
+jinja2_template(
+ name = "constants.json",
+ src = "constants.jinja2.json",
+ includes = [
+ "8971.json",
+ "common.json",
+ ],
+ parameters = {},
+ visibility = ["//visibility:public"],
+)
+
+jinja2_template(
+ name = "test_constants.json",
+ src = "test_constants.jinja2.json",
+ includes = glob(["test_data/*.json"]),
+ parameters = {},
+ visibility = ["//visibility:public"],
+)
+
+flatbuffer_cc_library(
+ name = "constants_fbs",
+ srcs = ["constants.fbs"],
+ gen_reflections = True,
+ visibility = ["//visibility:public"],
+)
+
+flatbuffer_cc_library(
+ name = "constants_list_fbs",
+ srcs = ["constants_list.fbs"],
+ gen_reflections = True,
+ visibility = ["//visibility:public"],
+ deps = [":constants_fbs"],
+)
+
+cc_binary(
+ name = "constants_sender",
+ srcs = ["constants_sender.cc"],
+ visibility = ["//visibility:public"],
+ deps = [
+ ":constants_fbs",
+ ":constants_list_fbs",
+ "//aos:init",
+ "//aos/events:shm_event_loop",
+ "//aos/testing:path",
+ "//frc971/constants:constants_sender_lib",
+ ],
+)
diff --git a/y2023_bot3/constants/common.json b/y2023_bot3/constants/common.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/y2023_bot3/constants/common.json
@@ -0,0 +1 @@
+{}
diff --git a/y2023_bot3/constants/constants.fbs b/y2023_bot3/constants/constants.fbs
new file mode 100644
index 0000000..08f03be
--- /dev/null
+++ b/y2023_bot3/constants/constants.fbs
@@ -0,0 +1,10 @@
+namespace y2023_bot3;
+
+table RobotConstants {
+}
+
+table Constants {
+ robot:RobotConstants (id: 0);
+}
+
+root_type Constants;
diff --git a/y2023_bot3/constants/constants.jinja2.json b/y2023_bot3/constants/constants.jinja2.json
new file mode 100644
index 0000000..be1ea14
--- /dev/null
+++ b/y2023_bot3/constants/constants.jinja2.json
@@ -0,0 +1,8 @@
+{
+ "constants": [
+ {
+ "team": 8971,
+ "data": {% include 'y2023_bot3/constants/8971.json' %}
+ },
+ ]
+}
diff --git a/y2023_bot3/constants/constants_list.fbs b/y2023_bot3/constants/constants_list.fbs
new file mode 100644
index 0000000..8b132e8
--- /dev/null
+++ b/y2023_bot3/constants/constants_list.fbs
@@ -0,0 +1,14 @@
+include "y2023_bot3/constants/constants.fbs";
+
+namespace y2023_bot3;
+
+table TeamAndConstants {
+ team:long (id: 0);
+ data:Constants (id: 1);
+}
+
+table ConstantsList {
+ constants:[TeamAndConstants] (id: 0);
+}
+
+root_type ConstantsList;
diff --git a/y2023_bot3/constants/constants_sender.cc b/y2023_bot3/constants/constants_sender.cc
new file mode 100644
index 0000000..d6e5c28
--- /dev/null
+++ b/y2023_bot3/constants/constants_sender.cc
@@ -0,0 +1,25 @@
+#include "gflags/gflags.h"
+#include "glog/logging.h"
+
+#include "aos/configuration.h"
+#include "aos/events/shm_event_loop.h"
+#include "aos/init.h"
+#include "aos/json_to_flatbuffer.h"
+#include "frc971/constants/constants_sender_lib.h"
+#include "y2023_bot3/constants/constants_generated.h"
+#include "y2023_bot3/constants/constants_list_generated.h"
+
+DEFINE_string(config, "aos_config.json", "Path to the AOS config.");
+DEFINE_string(constants_path, "constants.json", "Path to the constant file");
+
+int main(int argc, char **argv) {
+ aos::InitGoogle(&argc, &argv);
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig(FLAGS_config);
+ aos::ShmEventLoop event_loop(&config.message());
+ frc971::constants::ConstantSender<y2023_bot3::Constants,
+ y2023_bot3::ConstantsList>
+ constants_sender(&event_loop, FLAGS_constants_path);
+ // Don't need to call Run().
+ return 0;
+}
diff --git a/y2023_bot3/constants/simulated_constants_sender.cc b/y2023_bot3/constants/simulated_constants_sender.cc
new file mode 100644
index 0000000..36c1891
--- /dev/null
+++ b/y2023_bot3/constants/simulated_constants_sender.cc
@@ -0,0 +1,18 @@
+#include "aos/events/simulated_event_loop.h"
+#include "aos/testing/path.h"
+#include "frc971/constants/constants_sender_lib.h"
+#include "y2023_bot3/constants/constants_generated.h"
+#include "y2023_bot3/constants/constants_list_generated.h"
+
+namespace y2023_bot3 {
+bool SendSimulationConstants(aos::SimulatedEventLoopFactory *factory, int team,
+ std::string constants_path) {
+ for (const aos::Node *node : factory->nodes()) {
+ std::unique_ptr<aos::EventLoop> event_loop =
+ factory->MakeEventLoop("constants_sender", node);
+ frc971::constants::ConstantSender<Constants, ConstantsList> sender(
+ event_loop.get(), constants_path, team, "/constants");
+ }
+ return true;
+}
+} // namespace y2023_bot3
diff --git a/y2023_bot3/constants/simulated_constants_sender.h b/y2023_bot3/constants/simulated_constants_sender.h
new file mode 100644
index 0000000..3f1495f
--- /dev/null
+++ b/y2023_bot3/constants/simulated_constants_sender.h
@@ -0,0 +1,16 @@
+#ifndef Y2023_CONSTANTS_SIMULATED_CONFIG_SENDER_H_
+#define Y2023_CONSTANTS_SIMULATED_CONFIG_SENDER_H_
+
+#include "aos/events/simulated_event_loop.h"
+#include "aos/testing/path.h"
+
+namespace y2023_bot3 {
+// Returns true, to allow this to be easily called in the initializer list of a
+// constructor.
+bool SendSimulationConstants(
+ aos::SimulatedEventLoopFactory *factory, int team,
+ std::string constants_path =
+ aos::testing::ArtifactPath("y2023_bot3/constants/test_constants.json"));
+} // namespace y2023_bot3
+
+#endif // Y2023_CONSTANTS_SIMULATED_CONFIG_SENDER_H_
diff --git a/y2023_bot3/constants/test_constants.jinja2.json b/y2023_bot3/constants/test_constants.jinja2.json
new file mode 100644
index 0000000..f05194b
--- /dev/null
+++ b/y2023_bot3/constants/test_constants.jinja2.json
@@ -0,0 +1,8 @@
+{
+ "constants": [
+ {
+ "team": 7971,
+ "data": {% include 'y2023_bot3/constants/test_data/test_team.json' %}
+ }
+ ]
+}
diff --git a/y2023_bot3/constants/test_data/scoring_map.json b/y2023_bot3/constants/test_data/scoring_map.json
new file mode 100644
index 0000000..0967ef4
--- /dev/null
+++ b/y2023_bot3/constants/test_data/scoring_map.json
@@ -0,0 +1 @@
+{}
diff --git a/y2023_bot3/constants/test_data/test_team.json b/y2023_bot3/constants/test_data/test_team.json
new file mode 100644
index 0000000..97bab66
--- /dev/null
+++ b/y2023_bot3/constants/test_data/test_team.json
@@ -0,0 +1,3 @@
+{
+ "robot": {}
+}