Update y2022 configs to be multi-node

Signed-off-by: milind-u <milind.upadhyay@gmail.com>
Change-Id: Ice778cba24dcf6911d23d5c69a63f50cc2fa8a6f
diff --git a/y2022/BUILD b/y2022/BUILD
index 9dcd85d..2173877 100644
--- a/y2022/BUILD
+++ b/y2022/BUILD
@@ -1,17 +1,26 @@
 load("//frc971:downloader.bzl", "robot_downloader")
 load("//aos:config.bzl", "aos_config")
+load("//tools/build_rules:template.bzl", "jinja2_template")
 
 robot_downloader(
+    binaries = [
+        "//aos/network:web_proxy_main",
+    ],
     data = [
         ":config",
     ],
     start_binaries = [
+        "//aos/events/logging:logger_main",
+        "//aos/network:web_proxy_main",
         ":joystick_reader",
         ":wpilib_interface",
+        "//aos/network:message_bridge_client",
+        "//aos/network:message_bridge_server",
+        "//y2022/actors:binaries",
         "//y2022/control_loops/drivetrain:drivetrain",
         "//y2022/control_loops/superstructure:superstructure",
-        "//y2022/actors:binaries",
     ],
+    target_compatible_with = ["@platforms//os:linux"],
 )
 
 robot_downloader(
@@ -22,8 +31,6 @@
     data = [
         ":config",
     ],
-    dirs = [
-    ],
     start_binaries = [
         "//aos/events/logging:logger_main",
         "//aos/network:message_bridge_client",
@@ -35,6 +42,111 @@
     target_type = "pi",
 )
 
+aos_config(
+    name = "config",
+    src = "y2022.json",
+    flatbuffers = [
+        "//aos/network:message_bridge_client_fbs",
+        "//aos/network:message_bridge_server_fbs",
+        "//aos/network:timestamp_fbs",
+        "//frc971/input:robot_state_fbs",
+        "//frc971/vision:vision_fbs",
+    ],
+    target_compatible_with = ["@platforms//os:linux"],
+    visibility = ["//visibility:public"],
+    deps = [
+        ":config_logger",
+        ":config_pi1",
+        ":config_pi2",
+        ":config_pi3",
+        ":config_pi4",
+        ":config_pi5",
+        ":config_roborio",
+    ],
+)
+
+[
+    aos_config(
+        name = "config_" + pi,
+        src = "y2022_" + pi + ".json",
+        flatbuffers = [
+            "//aos/network:message_bridge_client_fbs",
+            "//aos/network:message_bridge_server_fbs",
+            "//aos/network:timestamp_fbs",
+            "//aos/network:remote_message_fbs",
+            "//frc971/vision:vision_fbs",
+            "//y2022/vision:target_estimate_fbs",
+        ],
+        target_compatible_with = ["@platforms//os:linux"],
+        visibility = ["//visibility:public"],
+        deps = [
+            "//aos/events:config",
+            "//frc971/control_loops/drivetrain:config",
+            "//frc971/input:config",
+        ],
+    )
+    for pi in [
+        "pi1",
+        "pi2",
+        "pi3",
+        "pi4",
+        "pi5",
+    ]
+]
+
+aos_config(
+    name = "config_logger",
+    src = "y2022_logger.json",
+    flatbuffers = [
+        "//aos/network:message_bridge_client_fbs",
+        "//aos/network:message_bridge_server_fbs",
+        "//aos/network:timestamp_fbs",
+        "//aos/network:remote_message_fbs",
+        "//frc971/vision:vision_fbs",
+    ],
+    target_compatible_with = ["@platforms//os:linux"],
+    visibility = ["//visibility:public"],
+    deps = [
+        "//aos/events:config",
+        "//frc971/control_loops/drivetrain:config",
+        "//frc971/input:config",
+    ],
+)
+
+aos_config(
+    name = "config_roborio",
+    src = "y2022_roborio.json",
+    flatbuffers = [
+        "//aos/network:remote_message_fbs",
+        "//aos/network:message_bridge_client_fbs",
+        "//aos/network:message_bridge_server_fbs",
+        "//aos/network:timestamp_fbs",
+        "//y2019/control_loops/drivetrain:target_selector_fbs",
+        "//y2022/control_loops/superstructure:superstructure_goal_fbs",
+        "//y2022/control_loops/superstructure:superstructure_output_fbs",
+        "//y2022/control_loops/superstructure:superstructure_position_fbs",
+        "//y2022/control_loops/superstructure:superstructure_status_fbs",
+    ],
+    target_compatible_with = ["@platforms//os:linux"],
+    deps = [
+        "//aos/events:config",
+        "//frc971/autonomous:config",
+        "//frc971/control_loops/drivetrain:config",
+        "//frc971/input:config",
+        "//frc971/wpilib:config",
+    ],
+)
+
+[
+    jinja2_template(
+        name = "y2022_pi" + str(num) + ".json",
+        src = "y2022_pi_template.json",
+        parameters = {"NUM": str(num)},
+        target_compatible_with = ["@platforms//os:linux"],
+    )
+    for num in range(1, 6)
+]
+
 cc_library(
     name = "constants",
     srcs = [
@@ -117,21 +229,3 @@
         "//y2022/control_loops/superstructure:superstructure_status_fbs",
     ],
 )
-
-aos_config(
-    name = "config",
-    src = "y2022.json",
-    flatbuffers = [
-        "//y2022/control_loops/superstructure:superstructure_goal_fbs",
-        "//y2022/control_loops/superstructure:superstructure_output_fbs",
-        "//y2022/control_loops/superstructure:superstructure_position_fbs",
-        "//y2022/control_loops/superstructure:superstructure_status_fbs",
-    ],
-    visibility = ["//visibility:public"],
-    deps = [
-        "//frc971/autonomous:config",
-        "//frc971/control_loops/drivetrain:config",
-        "//frc971/input:config",
-        "//frc971/wpilib:config",
-    ],
-)
diff --git a/y2022/vision/target_estimate.fbs b/y2022/vision/target_estimate.fbs
index 075c9c4..e22654a 100644
--- a/y2022/vision/target_estimate.fbs
+++ b/y2022/vision/target_estimate.fbs
@@ -10,3 +10,5 @@
 
   // TODO(milind): add confidence and blob stats
 }
+
+root_type TargetEstimate;
diff --git a/y2022/y2022.json b/y2022/y2022.json
index 4abbd5e..010c675 100644
--- a/y2022/y2022.json
+++ b/y2022/y2022.json
@@ -1,39 +1,23 @@
 {
-  "channels":
-  [
+  "channel_storage_duration": 2000000000,
+  "maps": [
     {
-      "name": "/superstructure",
-      "type": "y2022.control_loops.superstructure.Goal",
-      "frequency": 200
-    },
-    {
-      "name": "/superstructure",
-      "type": "y2022.control_loops.superstructure.Status",
-      "frequency": 200
-    },
-    {
-      "name": "/superstructure",
-      "type": "y2022.control_loops.superstructure.Output",
-      "frequency": 200
-    },
-    {
-      "name": "/superstructure",
-      "type": "y2022.control_loops.superstructure.Position",
-      "frequency": 200
-    }
-  ],
-  "applications": [
-    {
-      "name": "drivetrain"
-    },
-    {
-      "name": "superstructure"
+      "match": {
+        "name": "/aos",
+        "type": "aos.RobotState"
+      },
+      "rename": {
+        "name": "/roborio/aos"
+      }
     }
   ],
   "imports": [
-    "../frc971/input/robot_state_config.json",
-    "../frc971/control_loops/drivetrain/drivetrain_config.json",
-    "../frc971/autonomous/autonomous_config.json",
-    "../frc971/wpilib/wpilib_config.json"
+    "y2022_roborio.json",
+    "y2022_pi1.json",
+    "y2022_pi2.json",
+    "y2022_pi3.json",
+    "y2022_pi4.json",
+    "y2022_pi5.json",
+    "y2022_logger.json"
   ]
 }
diff --git a/y2022/y2022_pi_template.json b/y2022/y2022_pi_template.json
index e80d6c3..4994a36 100644
--- a/y2022/y2022_pi_template.json
+++ b/y2022/y2022_pi_template.json
@@ -104,7 +104,7 @@
       "source_node": "pi{{ NUM }}",
       "frequency": 25,
       "num_senders": 2
-    }
+    },
     {
       "name": "/logger/aos",
       "type": "aos.starter.StarterRpc",