Fix handling of special channels in log_to_mcap

Because RegisterWithoutStarting starts the clocks at 0.0, and because
the various options for creating startup handlers didn't obviously help
in this situation, fix the special configuration and timestamp channels
to not produce messages at t=0.0.

Change-Id: Ifaab480c7f37a6b9fea0317d3a5a529bdb3c3c86
Signed-off-by: James Kuszmaul <jabukuszmaul@gmail.com>
diff --git a/aos/util/mcap_logger.cc b/aos/util/mcap_logger.cc
index 88476ed..96a9b60 100644
--- a/aos/util/mcap_logger.cc
+++ b/aos/util/mcap_logger.cc
@@ -229,17 +229,6 @@
   // Manually add in a special /configuration channel.
   if (register_handlers == RegisterHandlers::kYes) {
     configuration_id_ = ++id;
-    event_loop_->OnRun([this]() {
-      // TODO(james): Make it so that the timestamp for the configuration
-      // message is not 0.0.
-      Context config_context;
-      config_context.monotonic_event_time = event_loop_->monotonic_now();
-      config_context.queue_index = 0;
-      config_context.size = configuration_.span().size();
-      config_context.data = configuration_.span().data();
-      WriteMessage(configuration_id_, &configuration_channel_.message(),
-                   config_context, &current_chunks_[configuration_id_]);
-    });
   }
 
   std::vector<SummaryOffset> offsets;
@@ -276,6 +265,18 @@
   return offsets;
 }
 
+void McapLogger::WriteConfigurationMessage() {
+  Context config_context;
+  config_context.monotonic_event_time = event_loop_->monotonic_now();
+  config_context.queue_index = 0;
+  config_context.size = configuration_.span().size();
+  config_context.data = configuration_.span().data();
+  // Avoid infinite recursion...
+  wrote_configuration_ = true;
+  WriteMessage(configuration_id_, &configuration_channel_.message(),
+               config_context, &current_chunks_[configuration_id_]);
+}
+
 void McapLogger::WriteMagic() { output_ << "\x89MCAP0\r\n"; }
 
 void McapLogger::WriteHeader() {
@@ -390,6 +391,9 @@
 
 void McapLogger::WriteMessage(uint16_t channel_id, const Channel *channel,
                               const Context &context, ChunkStatus *chunk) {
+  if (!wrote_configuration_) {
+    WriteConfigurationMessage();
+  }
   CHECK_NOTNULL(context.data);
 
   message_counts_[channel_id]++;