Implement UART serialization code to/from the cameras
Also fix a few things in the SPI serialization code I noticed while
reusing the pattern.
Change-Id: I645775b4c9ea1265025957e50b4d03f4932582f8
diff --git a/y2019/jevois/uart.h b/y2019/jevois/uart.h
index 04a1554..32ca110 100644
--- a/y2019/jevois/uart.h
+++ b/y2019/jevois/uart.h
@@ -3,6 +3,7 @@
#include "aos/containers/sized_array.h"
#include "third_party/optional/tl/optional.hpp"
+#include "y2019/jevois/cobs.h"
#include "y2019/jevois/structures.h"
// This file manages serializing and deserializing the various structures for
@@ -11,14 +12,27 @@
namespace frc971 {
namespace jevois {
-constexpr size_t uart_max_size() {
- // TODO(Brian): Make this real.
- return 10;
+constexpr size_t uart_to_teensy_size() {
+ return 3 /* targets */ * (sizeof(float) * 4 /* fields */) + 1 /* age */ +
+ 2 /* CRC-16 */;
}
-using UartBuffer = aos::SizedArray<char, uart_max_size()>;
+using UartToTeensyBuffer =
+ aos::SizedArray<char, CobsMaxEncodedSize(uart_to_teensy_size())>;
-UartBuffer UartPackToTeensy(const Frame &message);
-tl::optional<CameraCalibration> UartUnpackToCamera(const UartBuffer &message);
+constexpr size_t uart_to_camera_size() {
+ return sizeof(float) * 3 * 4 /* calibration */ +
+ sizeof(int64_t) /* teensy_now */ + sizeof(int64_t) /* realtime_now */ +
+ 1 /* camera_command */ + 2 /* CRC-16 */;
+}
+using UartToCameraBuffer =
+ aos::SizedArray<char, CobsMaxEncodedSize(uart_to_camera_size())>;
+
+UartToTeensyBuffer UartPackToTeensy(const Frame &message);
+tl::optional<Frame> UartUnpackToTeensy(const UartToTeensyBuffer &buffer);
+
+UartToCameraBuffer UartPackToCamera(const CameraCalibration &message);
+tl::optional<CameraCalibration> UartUnpackToCamera(
+ const UartToCameraBuffer &buffer);
} // namespace jevois
} // namespace frc971