Convert aos over to flatbuffers
Everything builds, and all the tests pass. I suspect that some entries
are missing from the config files, but those will be found pretty
quickly on startup.
There is no logging or live introspection of queue messages.
Change-Id: I496ee01ed68f202c7851bed7e8786cee30df29f5
diff --git a/y2017/vision/BUILD b/y2017/vision/BUILD
index 83447e3..1997870 100644
--- a/y2017/vision/BUILD
+++ b/y2017/vision/BUILD
@@ -1,14 +1,15 @@
-load("//aos/build:queues.bzl", "queue_library")
+load("@com_github_google_flatbuffers//:build_defs.bzl", "flatbuffer_cc_library")
load("//tools/build_rules:gtk_dependent.bzl", "gtk_dependent_cc_binary", "gtk_dependent_cc_library")
load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library")
package(default_visibility = ["//visibility:public"])
-queue_library(
- name = "vision_queue",
+flatbuffer_cc_library(
+ name = "vision_fbs",
srcs = [
- "vision.q",
+ "vision.fbs",
],
+ gen_reflections = 1,
visibility = ["//visibility:public"],
)
@@ -58,12 +59,11 @@
visibility = ["//visibility:public"],
deps = [
":target_finder",
- ":vision_queue",
+ ":vision_fbs",
":vision_result",
"//aos:init",
- "//aos/events:shm-event-loop",
+ "//aos/events:shm_event_loop",
"//aos/logging",
- "//aos/logging:queue_logging",
"//aos/mutex",
"//aos/time",
"//aos/vision/events:udp",
diff --git a/y2017/vision/target_receiver.cc b/y2017/vision/target_receiver.cc
index 6b86972..e96fba9 100644
--- a/y2017/vision/target_receiver.cc
+++ b/y2017/vision/target_receiver.cc
@@ -1,13 +1,12 @@
#include <netdb.h>
-#include "aos/events/shm-event-loop.h"
+#include "aos/events/shm_event_loop.h"
#include "aos/init.h"
#include "aos/logging/logging.h"
-#include "aos/logging/queue_logging.h"
#include "aos/time/time.h"
#include "aos/vision/events/udp.h"
#include "y2017/vision/target_finder.h"
-#include "y2017/vision/vision.q.h"
+#include "y2017/vision/vision_generated.h"
#include "y2017/vision/vision_result.pb.h"
namespace y2017 {
@@ -20,11 +19,13 @@
char raw_data[65507];
// TODO(parker): Have this pull in a config from somewhere.
TargetFinder finder;
- ::aos::ShmEventLoop event_loop;
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig("config.json");
+
+ ::aos::ShmEventLoop event_loop(&config.message());
::aos::Sender<::y2017::vision::VisionStatus> vision_status_sender =
- event_loop.MakeSender<::y2017::vision::VisionStatus>(
- ".y2017.vision.vision_status");
+ event_loop.MakeSender<::y2017::vision::VisionStatus>("/vision");
while (true) {
// TODO(austin): Don't malloc.
@@ -42,22 +43,27 @@
continue;
}
- auto new_vision_status = vision_status_sender.MakeMessage();
- new_vision_status->image_valid = target.has_target();
- if (new_vision_status->image_valid) {
- new_vision_status->target_time =
+ auto builder = vision_status_sender.MakeBuilder();
+ VisionStatus::Builder vision_status_builder =
+ builder.MakeBuilder<VisionStatus>();
+ vision_status_builder.add_image_valid(target.has_target());
+ if (target.has_target()) {
+ vision_status_builder.add_target_time (
std::chrono::duration_cast<std::chrono::nanoseconds>(
target_time.time_since_epoch())
- .count();
+ .count());
+ double distance = 0.0;
+ double angle = 0.0;
finder.GetAngleDist(
aos::vision::Vector<2>(target.target().x(), target.target().y()),
/* TODO: Insert down estimate here in radians: */ 0.0,
- &new_vision_status->distance, &new_vision_status->angle);
+ &distance, &angle);
+ vision_status_builder.add_distance(distance);
+ vision_status_builder.add_angle(angle);
}
- AOS_LOG_STRUCT(DEBUG, "vision", *new_vision_status);
- if (!new_vision_status.Send()) {
+ if (!builder.Send(vision_status_builder.Finish())) {
AOS_LOG(ERROR, "Failed to send vision information\n");
}
}
diff --git a/y2017/vision/vision.fbs b/y2017/vision/vision.fbs
new file mode 100644
index 0000000..f1bc013
--- /dev/null
+++ b/y2017/vision/vision.fbs
@@ -0,0 +1,16 @@
+namespace y2017.vision;
+
+// Published on ".y2017.vision.vision_status"
+table VisionStatus {
+ image_valid:bool;
+
+ // Distance to the target in meters.
+ distance:double;
+ // The angle in radians of the bottom of the target.
+ angle:double;
+
+ // Capture time of the angle using the clock behind monotonic_clock::now().
+ target_time:long;
+}
+
+root_type VisionStatus;
diff --git a/y2017/vision/vision.q b/y2017/vision/vision.q
deleted file mode 100644
index 6e4a02a..0000000
--- a/y2017/vision/vision.q
+++ /dev/null
@@ -1,14 +0,0 @@
-package y2017.vision;
-
-// Published on ".y2017.vision.vision_status"
-message VisionStatus {
- bool image_valid;
-
- // Distance to the target in meters.
- double distance;
- // The angle in radians of the bottom of the target.
- double angle;
-
- // Capture time of the angle using the clock behind monotonic_clock::now().
- int64_t target_time;
-};