Make target_sender send data out the UART

Change-Id: Ibd91fce330788c22db77adc3e6fee525af16909e
diff --git a/y2019/jevois/BUILD b/y2019/jevois/BUILD
index 0e0d3bd..9304e8e 100644
--- a/y2019/jevois/BUILD
+++ b/y2019/jevois/BUILD
@@ -76,6 +76,7 @@
     hdrs = [
         "spi.h",
     ],
+    visibility = ["//visibility:public"],
     deps = [
         ":jevois_crc",
         ":structures",
@@ -94,6 +95,7 @@
     hdrs = [
         "uart.h",
     ],
+    visibility = ["//visibility:public"],
     deps = [
         ":cobs",
         ":jevois_crc",
diff --git a/y2019/vision/BUILD b/y2019/vision/BUILD
index 6736c24..f727d4b 100644
--- a/y2019/vision/BUILD
+++ b/y2019/vision/BUILD
@@ -4,28 +4,39 @@
 
 package(default_visibility = ["//visibility:public"])
 
-VISION_TARGETS = [ "//tools:k8", "//tools:armhf-debian"]
+VISION_TARGETS = [
+    "//tools:k8",
+    "//tools:armhf-debian",
+]
 
 cc_library(
     name = "target_finder",
-    srcs = ["target_finder.cc", "target_geometry.cc"],
-    hdrs = ["target_finder.h", "target_types.h"],
+    srcs = [
+        "target_finder.cc",
+        "target_geometry.cc",
+    ],
+    hdrs = [
+        "target_finder.h",
+        "target_types.h",
+    ],
+    restricted_to = VISION_TARGETS,
     deps = [
-        "@com_google_ceres_solver//:ceres",
+        "//aos/vision/blob:contour",
         "//aos/vision/blob:hierarchical_contour_merge",
         "//aos/vision/blob:region_alloc",
-        "//aos/vision/blob:contour",
         "//aos/vision/blob:threshold",
         "//aos/vision/blob:transpose",
         "//aos/vision/debug:overlay",
         "//aos/vision/math:vector",
+        "@com_google_ceres_solver//:ceres",
     ],
-    restricted_to = VISION_TARGETS,
 )
 
 gtk_dependent_cc_binary(
     name = "debug_viewer",
     srcs = ["debug_viewer.cc"],
+    copts = ["-Wno-unused-variable"],
+    restricted_to = VISION_TARGETS,
     deps = [
         ":target_finder",
         "//aos/vision/blob:move_scale",
@@ -34,28 +45,28 @@
         "//aos/vision/debug:debug_framework",
         "//aos/vision/math:vector",
     ],
-    copts = ["-Wno-unused-variable"],
-    restricted_to = VISION_TARGETS,
 )
 
 cc_binary(
     name = "target_sender",
     srcs = ["target_sender.cc"],
-    deps = [
-         ":target_finder",
-         "//y2019/jevois:serial",
-         "//aos/logging",
-         "//aos/logging:implementations",
-         "//aos/vision/blob:find_blob",
-         "//aos/vision/blob:codec",
-         "//aos/vision/events:epoll_events",
-         "//aos/vision/events:socket_types",
-         "//aos/vision/events:udp",
-         "//aos/vision/image:image_stream",
-         "//aos/vision/image:reader",
-         "@com_google_ceres_solver//:ceres",
-    ],
     restricted_to = VISION_TARGETS,
+    deps = [
+        ":target_finder",
+        "//aos/logging",
+        "//aos/logging:implementations",
+        "//aos/vision/blob:codec",
+        "//aos/vision/blob:find_blob",
+        "//aos/vision/events:epoll_events",
+        "//aos/vision/events:socket_types",
+        "//aos/vision/events:udp",
+        "//aos/vision/image:image_stream",
+        "//aos/vision/image:reader",
+        "//y2019/jevois:serial",
+        "//y2019/jevois:structures",
+        "//y2019/jevois:uart",
+        "@com_google_ceres_solver//:ceres",
+    ],
 )
 
 """
diff --git a/y2019/vision/target_sender.cc b/y2019/vision/target_sender.cc
index 0d53e2c..a4762bb 100644
--- a/y2019/vision/target_sender.cc
+++ b/y2019/vision/target_sender.cc
@@ -10,6 +10,8 @@
 #include "aos/vision/image/reader.h"
 
 #include "y2019/jevois/serial.h"
+#include "y2019/jevois/structures.h"
+#include "y2019/jevois/uart.h"
 #include "y2019/vision/target_finder.h"
 
 using ::aos::events::DataSocket;
@@ -74,8 +76,8 @@
       new ::aos::logging::StreamLogImplementation(stderr));
 
   int itsDev = open_terminos("/dev/ttyS0");
-  dup2(itsDev, 1);
-  dup2(itsDev, 2);
+  //dup2(itsDev, 1);
+  //dup2(itsDev, 2);
 
   TargetFinder finder_;
 
@@ -121,6 +123,18 @@
     }
 
     results = finder_.FilterResults(results);
+
+    // If we succeed in writing our delimiter, then write out the rest of the
+    // frame. If not, no point in continuing.
+    if (write(itsDev, "\0", 1) == 1) {
+      frc971::jevois::Frame frame{};
+      // TODO(Parker): Fill out frame appropriately.
+      const auto serialized_frame = frc971::jevois::UartPackToTeensy(frame);
+      // We don't really care if this succeeds or not. If it fails for some
+      // reason, we'll just try again with the next frame, and the other end
+      // will find the new packet just fine.
+      (void)write(itsDev, serialized_frame.data(), serialized_frame.size());
+    }
   };
 
   aos::events::EpollLoop loop;