Start filesystem_monitor and fix irq_affinity on orins

Makes it so that the image_logger will stop logging when there is
relatively little space remaining.

Change-Id: I6b1482cf6c0600bcdc03657696e16e1ac8988f0f
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/y2024/BUILD b/y2024/BUILD
index e3fbb72..704a5a4 100644
--- a/y2024/BUILD
+++ b/y2024/BUILD
@@ -55,6 +55,7 @@
         "//aos/util:foxglove_websocket",
         "//frc971/image_streamer:image_streamer",
         "//frc971/vision:intrinsics_calibration",
+        "//aos/util:filesystem_monitor",
         "//y2024/vision:viewer",
         "//y2024/constants:constants_sender",
         "//y2024/localizer:localizer_main",
@@ -63,7 +64,7 @@
     ],
     data = [
         ":aos_config",
-        "//frc971/rockpi:rockpi_config.json",
+        "//frc971/orin:orin_irq_config.json",
         "//y2024/constants:constants.json",
         "//y2024/vision:image_streamer_start",
         "//y2024/www:www_files",
diff --git a/y2024/vision/BUILD b/y2024/vision/BUILD
index d36c956..4904554 100644
--- a/y2024/vision/BUILD
+++ b/y2024/vision/BUILD
@@ -60,6 +60,7 @@
         "//aos/events:shm_event_loop",
         "//aos/events/logging:log_writer",
         "//aos/logging:log_namer",
+        "//aos/util:filesystem_fbs",
         "//frc971/input:joystick_state_fbs",
         "@com_github_gflags_gflags//:gflags",
         "@com_github_google_glog//:glog",
diff --git a/y2024/vision/image_logger.cc b/y2024/vision/image_logger.cc
index 55a4e12..2984824 100644
--- a/y2024/vision/image_logger.cc
+++ b/y2024/vision/image_logger.cc
@@ -9,6 +9,7 @@
 #include "aos/events/shm_event_loop.h"
 #include "aos/init.h"
 #include "aos/logging/log_namer.h"
+#include "aos/util/filesystem_generated.h"
 #include "frc971/input/joystick_state_generated.h"
 
 DEFINE_string(config, "aos_config.json", "Config file to use.");
@@ -48,10 +49,13 @@
 
   aos::ShmEventLoop event_loop(&config.message());
 
+  aos::Fetcher<aos::util::FilesystemStatus> filesystem_status =
+      event_loop.MakeFetcher<aos::util::FilesystemStatus>("/aos");
+
   bool logging = false;
   bool enabled = false;
   aos::monotonic_clock::time_point last_disable_time =
-      event_loop.monotonic_now();
+      aos::monotonic_clock::min_time;
   aos::monotonic_clock::time_point last_rotation_time =
       event_loop.monotonic_now();
   aos::logger::Logger logger(&event_loop);
@@ -76,13 +80,36 @@
   event_loop.MakeWatcher(
       "/imu/aos", [&](const aos::JoystickState &joystick_state) {
         const auto timestamp = event_loop.context().monotonic_event_time;
+        filesystem_status.Fetch();
+
         // Store the last time we got disabled
         if (enabled && !joystick_state.enabled()) {
           last_disable_time = timestamp;
         }
         enabled = joystick_state.enabled();
 
-        if (!logging && enabled) {
+        bool enough_space = true;
+
+        if (filesystem_status.get() != nullptr) {
+          enough_space = false;
+          for (const aos::util::Filesystem *fs :
+               *filesystem_status->filesystems()) {
+            CHECK(fs->has_path());
+            if (fs->path()->string_view() == "/") {
+              if (fs->free_space() > 50ull * 1024ull * 1024ull * 1024ull) {
+                enough_space = true;
+              }
+            }
+          }
+        }
+
+        const bool should_be_logging =
+            (enabled ||
+             timestamp < last_disable_time + std::chrono::duration<double>(
+                                                 FLAGS_disabled_time)) &&
+            enough_space;
+
+        if (!logging && should_be_logging) {
           auto log_namer = MakeLogNamer(&event_loop);
           if (log_namer == nullptr) {
             return;
@@ -93,9 +120,7 @@
           logger.StartLogging(std::move(log_namer));
           logging = true;
           last_rotation_time = event_loop.monotonic_now();
-        } else if (logging && !enabled &&
-                   (timestamp - last_disable_time) >
-                       std::chrono::duration<double>(FLAGS_disabled_time)) {
+        } else if (logging && !should_be_logging) {
           // Stop logging if we've been disabled for a non-negligible amount of
           // time
           LOG(INFO) << "Stopping logging";
diff --git a/y2024/y2024_imu.json b/y2024/y2024_imu.json
index 5990242..62254e1 100644
--- a/y2024/y2024_imu.json
+++ b/y2024/y2024_imu.json
@@ -41,8 +41,8 @@
       "type": "aos.timing.Report",
       "source_node": "imu",
       "frequency": 50,
-      "num_senders": 20,
-      "max_size": 6184
+      "num_senders": 30,
+      "max_size": 8192
     },
     {
       "name": "/imu/aos",
@@ -346,6 +346,22 @@
       ]
     },
     {
+      "name": "irq_affinity",
+      "executable_name": "irq_affinity",
+      "user": "root",
+      "args": ["--user=pi", "--irq_config=orin_irq_config.json"],
+      "nodes": [
+          "imu"
+      ]
+    },
+    {
+      "name": "filesystem_monitor",
+      "executable_name": "filesystem_monitor",
+      "nodes": [
+          "imu"
+      ]
+    },
+    {
       "name": "joystick_republish",
       "executable_name": "joystick_republish",
       "user": "pi",
diff --git a/y2024/y2024_orin1.json b/y2024/y2024_orin1.json
index 01dae9e..0b2c6af 100644
--- a/y2024/y2024_orin1.json
+++ b/y2024/y2024_orin1.json
@@ -11,7 +11,7 @@
       "type": "aos.timing.Report",
       "source_node": "orin1",
       "frequency": 50,
-      "num_senders": 20,
+      "num_senders": 30,
       "max_size": 8192
     },
     {
@@ -267,7 +267,14 @@
       "name": "irq_affinity",
       "executable_name": "irq_affinity",
       "user": "root",
-      "args": ["--user=pi"],
+      "args": ["--user=pi", "--irq_config=orin_irq_config.json"],
+      "nodes": [
+          "orin1"
+      ]
+    },
+    {
+      "name": "filesystem_monitor",
+      "executable_name": "filesystem_monitor",
       "nodes": [
           "orin1"
       ]