Merge "Adding intrinsic calibration files for first 4 cameras"
diff --git a/aos/BUILD b/aos/BUILD
index 4d041ca..7c0ad3d 100644
--- a/aos/BUILD
+++ b/aos/BUILD
@@ -239,6 +239,7 @@
srcs = ["configuration.fbs"],
target_compatible_with = ["@platforms//os:linux"],
visibility = ["//visibility:public"],
+ deps = ["//aos/flatbuffers/reflection:reflection_fbs"],
)
cc_static_flatbuffer(
diff --git a/aos/configuration.fbs b/aos/configuration.fbs
index 0b42f5b..b2b34c1 100644
--- a/aos/configuration.fbs
+++ b/aos/configuration.fbs
@@ -169,6 +169,10 @@
// If set, this is the memory limit to enforce in bytes for the application
// (and it's children)
memory_limit:uint64 = 0 (id: 8);
+
+ // If set, this is the number of nanoseconds the application has to stop. If the application
+ // doesn't stop within the specified time, then it is killed.
+ stop_time:int64 = 1000000000 (id: 9);
}
// Per node data and connection information.
diff --git a/aos/events/logging/log_backend_test.cc b/aos/events/logging/log_backend_test.cc
index d3c83cc..1e95c10 100644
--- a/aos/events/logging/log_backend_test.cc
+++ b/aos/events/logging/log_backend_test.cc
@@ -128,7 +128,17 @@
TEST(QueueAlignmentTest, Cases) {
QueueAligner aligner;
- uint8_t *start = nullptr;
+
+ // Get a 512-byte-aligned pointer to a buffer. That buffer needs to be at
+ // least 3 sectors big for the purposes of this test.
+ uint8_t buffer[FileHandler::kSector * 4];
+ void *aligned_start = buffer;
+ size_t size = sizeof(buffer);
+ ASSERT_TRUE(std::align(FileHandler::kSector, FileHandler::kSector * 3,
+ aligned_start, size) != nullptr);
+ ASSERT_GE(size, FileHandler::kSector * 3);
+
+ uint8_t *start = static_cast<uint8_t *>(aligned_start);
{
// Only prefix
std::vector<absl::Span<const uint8_t>> queue;
diff --git a/aos/events/logging/logfile_utils_out_of_space_test.sh b/aos/events/logging/logfile_utils_out_of_space_test.sh
index f412e0d..6a32347 100755
--- a/aos/events/logging/logfile_utils_out_of_space_test.sh
+++ b/aos/events/logging/logfile_utils_out_of_space_test.sh
@@ -23,7 +23,7 @@
rm -rf "${TMPFS}"
mkdir "${TMPFS}"
-function test {
+function run_test {
SIZE="$1"
echo "Running test with ${SIZE}..." >&2
unshare --mount --map-root-user bash <<END
@@ -37,10 +37,10 @@
}
# Run out of space exactly at the beginning of a block.
-test 81920
+run_test 81920
# Run out of space 1 byte into a block.
-test 81921
+run_test 81921
# Run out of space in the middle of a block.
-test 87040
+run_test 87040
diff --git a/aos/events/logging/multinode_logger_test_lib.h b/aos/events/logging/multinode_logger_test_lib.h
index 63604d6..8f64f66 100644
--- a/aos/events/logging/multinode_logger_test_lib.h
+++ b/aos/events/logging/multinode_logger_test_lib.h
@@ -76,13 +76,13 @@
};
constexpr std::string_view kCombinedConfigSha1() {
- return "32514f3a686e5f8936cc4651e7c81350112f7be8d80dcb8d4afaa29d233c5619";
+ return "71eb8341221fbabefb4ddde43bcebf794fd5855e3ad77786a1db0f9e27a39091";
}
constexpr std::string_view kSplitConfigSha1() {
- return "416da222c09d83325c6f453591d34c7ef12c12c2dd129ddeea657c4bec61b7fd";
+ return "f61d45dc0bda026e852e2da9b3e5c2c7f1c89c9f7958cfba3d02e2c960416f04";
}
constexpr std::string_view kReloggedSplitConfigSha1() {
- return "3fe428684a38298d3323ef087f44517574da3f07dd84b3740829156d6d870108";
+ return "3d8fd3d13955b517ee3d66a50b5e4dd7a13fd648f469d16910990418bcfc6beb";
}
LoggerState MakeLoggerState(NodeEventLoopFactory *node,
diff --git a/aos/flatbuffers.h b/aos/flatbuffers.h
index a299fe9..607303c 100644
--- a/aos/flatbuffers.h
+++ b/aos/flatbuffers.h
@@ -118,6 +118,11 @@
// make attempts to use it fail more obviously.
void Wipe() { memset(span().data(), 0, span().size()); }
+ // Returns true if the flatbuffer is valid. Returns false if either:
+ // * The flatbuffer is incorrectly constructed (e.g., it points to memory
+ // locations outside of the current memory buffer).
+ // * The flatbuffer is too complex, and the flatbuffer verifier chosen to bail
+ // when attempting to traverse the tree of tables.
bool Verify() const {
if (span().size() < 4u) {
return false;
diff --git a/aos/flatbuffers/BUILD b/aos/flatbuffers/BUILD
index 08d548f..32f1d39 100644
--- a/aos/flatbuffers/BUILD
+++ b/aos/flatbuffers/BUILD
@@ -102,6 +102,7 @@
":test_schema",
"//aos:flatbuffers",
"//aos:json_to_flatbuffer",
+ "//aos/flatbuffers/test_dir:include_reflection_fbs",
"//aos/flatbuffers/test_dir:type_coverage_fbs",
"//aos/testing:googletest",
"//aos/testing:path",
diff --git a/aos/flatbuffers/builder.h b/aos/flatbuffers/builder.h
index db89d10..36225c0 100644
--- a/aos/flatbuffers/builder.h
+++ b/aos/flatbuffers/builder.h
@@ -77,6 +77,9 @@
FlatbufferSpan<typename T::Flatbuffer> AsFlatbufferSpan() {
return {buffer()};
}
+ FlatbufferSpan<const typename T::Flatbuffer> AsFlatbufferSpan() const {
+ return {buffer()};
+ }
// Returns true if the flatbuffer is validly constructed. Should always return
// true (barring some sort of memory corruption). Exposed for convenience.
diff --git a/aos/flatbuffers/reflection/BUILD.bazel b/aos/flatbuffers/reflection/BUILD.bazel
new file mode 100644
index 0000000..475f2a2
--- /dev/null
+++ b/aos/flatbuffers/reflection/BUILD.bazel
@@ -0,0 +1,18 @@
+load("@aspect_bazel_lib//lib:copy_file.bzl", "copy_file")
+load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
+
+copy_file(
+ name = "reflection_fbs_copy",
+ src = "@com_github_google_flatbuffers//reflection:reflection_fbs_schema",
+ out = "reflection.fbs",
+)
+
+# This autogenerates both a reflection_static.h and a reflection_generated.h.
+# However, in order to avoid having two conflicting headers floating around,
+# we forcibly override the #include to use flatbuffers/reflection_generated.h
+# in static_flatbuffers.cc
+static_flatbuffer(
+ name = "reflection_fbs",
+ srcs = ["reflection.fbs"],
+ visibility = ["//visibility:public"],
+)
diff --git a/aos/flatbuffers/static_flatbuffers.cc b/aos/flatbuffers/static_flatbuffers.cc
index 8d8942c..c1b617f 100644
--- a/aos/flatbuffers/static_flatbuffers.cc
+++ b/aos/flatbuffers/static_flatbuffers.cc
@@ -19,6 +19,8 @@
bool is_inline = true;
// Whether this is a struct or not.
bool is_struct = false;
+ // Whether this is a repeated type (vector or string).
+ bool is_repeated = false;
// Full C++ type of this field.
std::string full_type = "";
// Full flatbuffer type for this field.
@@ -118,6 +120,22 @@
const std::string IncludePathForFbs(
std::string_view fbs_file, std::string_view include_suffix = "static") {
+ // Special case for the reflection_generated.h, which is checked into the
+ // repo.
+ // Note that we *do* autogenerated the reflection_static.h but that because
+ // it uses a special import path, we end up overriding the include anyways
+ // (note that we could muck around with the paths on the bazel side to instead
+ // get a cc_library with the correct include paths specified, although it is
+ // not clear that that would be any simpler than the extra else-if).
+ if (fbs_file == "reflection/reflection.fbs") {
+ if (include_suffix == "generated") {
+ return "flatbuffers/reflection_generated.h";
+ } else if (include_suffix == "static") {
+ return "aos/flatbuffers/reflection/reflection_static.h";
+ } else {
+ LOG(FATAL) << "This should be unreachable.";
+ }
+ }
fbs_file.remove_suffix(4);
return absl::StrCat(fbs_file, "_", include_suffix, ".h");
}
@@ -151,12 +169,14 @@
// straightforwards.
field->is_inline = true;
field->is_struct = false;
+ field->is_repeated = false;
field->full_type =
ScalarOrEnumType(schema, type->base_type(), type->index());
return;
case reflection::BaseType::String: {
field->is_inline = false;
field->is_struct = false;
+ field->is_repeated = true;
field->full_type =
absl::StrFormat("::aos::fbs::String<%d>",
GetLengthAttributeOrZero(field_fbs, "static_length"));
@@ -166,6 +186,7 @@
// We need to extract the name of the elements of the vector.
std::string element_type;
bool elements_are_inline = true;
+ field->is_repeated = true;
if (type->base_type() == reflection::BaseType::Vector) {
switch (type->element()) {
case reflection::BaseType::Obj: {
@@ -207,6 +228,7 @@
const reflection::Object *object = GetObject(schema, type->index());
field->is_inline = object->is_struct();
field->is_struct = object->is_struct();
+ field->is_repeated = false;
const std::string flatbuffer_name =
FlatbufferNameToCppName(object->name()->string_view());
if (field->is_inline) {
@@ -437,27 +459,97 @@
absl::StrJoin(clearers, "\n"));
}
+// Creates the FromFlatbuffer() method that copies from a flatbuffer object API
+// object (i.e., the FlatbufferT types).
+std::string MakeObjectCopier(const std::vector<FieldData> &fields) {
+ std::vector<std::string> copiers;
+ for (const FieldData &field : fields) {
+ if (field.is_struct) {
+ // Structs are stored as unique_ptr<FooStruct>
+ copiers.emplace_back(absl::StrFormat(R"code(
+ if (other.%s) {
+ set_%s(*other.%s);
+ }
+ )code",
+ field.name, field.name, field.name));
+ } else if (field.is_inline) {
+ // Inline non-struct elements are stored as FooType.
+ copiers.emplace_back(absl::StrFormat(R"code(
+ set_%s(other.%s);
+ )code",
+ field.name, field.name));
+ } else if (field.is_repeated) {
+ // strings are stored as std::string's.
+ // vectors are stored as std::vector's.
+ copiers.emplace_back(absl::StrFormat(R"code(
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_%s())->FromFlatbuffer(other.%s)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+ )code",
+ field.name, field.name));
+ } else {
+ // Tables are stored as unique_ptr<FooTable>
+ copiers.emplace_back(absl::StrFormat(R"code(
+ if (other.%s) {
+ if (!CHECK_NOTNULL(add_%s())->FromFlatbuffer(*other.%s)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+ }
+ )code",
+ field.name, field.name, field.name));
+ }
+ }
+ return absl::StrFormat(
+ R"code(
+ // Copies the contents of the provided flatbuffer into this flatbuffer,
+ // returning true on success.
+ // Because the Flatbuffer Object API does not provide any concept of an
+ // optionally populated scalar field, all scalar fields will be populated
+ // after a call to FromFlatbufferObject().
+ // This is a deep copy, and will call FromFlatbufferObject on
+ // any constituent objects.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer::NativeTableType &other) {
+ Clear();
+ %s
+ return true;
+ }
+ [[nodiscard]] bool FromFlatbuffer(const flatbuffers::unique_ptr<Flatbuffer::NativeTableType>& other) {
+ return FromFlatbuffer(*other);
+ }
+)code",
+ absl::StrJoin(copiers, "\n"));
+}
+
+// Creates the FromFlatbuffer() method that copies from an actual flatbuffer
+// object.
std::string MakeCopier(const std::vector<FieldData> &fields) {
std::vector<std::string> copiers;
for (const FieldData &field : fields) {
if (field.is_struct) {
copiers.emplace_back(absl::StrFormat(R"code(
- if (other->has_%s()) {
- set_%s(*other->%s());
+ if (other.has_%s()) {
+ set_%s(*other.%s());
}
)code",
field.name, field.name, field.name));
} else if (field.is_inline) {
copiers.emplace_back(absl::StrFormat(R"code(
- if (other->has_%s()) {
- set_%s(other->%s());
+ if (other.has_%s()) {
+ set_%s(other.%s());
}
)code",
field.name, field.name, field.name));
} else {
copiers.emplace_back(absl::StrFormat(R"code(
- if (other->has_%s()) {
- if (!CHECK_NOTNULL(add_%s())->FromFlatbuffer(other->%s())) {
+ if (other.has_%s()) {
+ if (!CHECK_NOTNULL(add_%s())->FromFlatbuffer(other.%s())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
@@ -473,11 +565,16 @@
// returning true on success.
// This is a deep copy, and will call FromFlatbuffer on any constituent
// objects.
- [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer &other) {
Clear();
%s
return true;
}
+ // Equivalent to FromFlatbuffer(const Flatbuffer&); this overload is provided
+ // to ease implementation of the aos::fbs::Vector internals.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ return FromFlatbuffer(*CHECK_NOTNULL(other));
+ }
)code",
absl::StrJoin(copiers, "\n"));
}
@@ -689,6 +786,7 @@
public:
// The underlying "raw" flatbuffer type for this type.
typedef %s Flatbuffer;
+ typedef flatbuffers::unique_ptr<Flatbuffer::NativeTableType> FlatbufferObjectType;
// Returns this object as a flatbuffer type. This reference may not be valid
// following mutations to the underlying flatbuffer, due to how memory may get
// may get moved around.
@@ -699,6 +797,7 @@
%s
%s
%s
+%s
private:
%s
%s
@@ -708,7 +807,7 @@
)code",
type_namespace, type_name, FlatbufferNameToCppName(fbs_type_name),
constants, MakeConstructor(type_name), type_name, accessors,
- MakeFullClearer(fields), MakeCopier(fields),
+ MakeFullClearer(fields), MakeCopier(fields), MakeObjectCopier(fields),
MakeMoveConstructor(type_name), members, MakeSubObjectList(fields));
GeneratedObject result;
diff --git a/aos/flatbuffers/static_flatbuffers_test.cc b/aos/flatbuffers/static_flatbuffers_test.cc
index fd95db3..52fa01e 100644
--- a/aos/flatbuffers/static_flatbuffers_test.cc
+++ b/aos/flatbuffers/static_flatbuffers_test.cc
@@ -10,6 +10,7 @@
#include "aos/flatbuffers.h"
#include "aos/flatbuffers/builder.h"
#include "aos/flatbuffers/interesting_schemas.h"
+#include "aos/flatbuffers/test_dir/include_reflection_static.h"
#include "aos/flatbuffers/test_dir/type_coverage_static.h"
#include "aos/flatbuffers/test_schema.h"
#include "aos/flatbuffers/test_static.h"
@@ -1042,4 +1043,55 @@
TestMemory(builder.buffer());
}
+// Uses a small example to manually verify that we can copy from the flatbuffer
+// object API.
+TEST_F(StaticFlatbuffersTest, ObjectApiCopy) {
+ aos::fbs::testing::TestTableT object_t;
+ object_t.scalar = 971;
+ object_t.vector_of_strings.push_back("971");
+ object_t.vector_of_structs.push_back({1, 2});
+ object_t.subtable = std::make_unique<SubTableT>();
+ aos::fbs::VectorAllocator allocator;
+ Builder<TestTableStatic> builder(&allocator);
+ ASSERT_TRUE(builder->FromFlatbuffer(object_t));
+ ASSERT_TRUE(builder.AsFlatbufferSpan().Verify());
+ // Note that vectors and strings get set to zero-length, but present, values.
+ EXPECT_EQ(
+ "{ \"scalar\": 971, \"vector_of_scalars\": [ ], \"string\": \"\", "
+ "\"vector_of_strings\": [ \"971\" ], \"subtable\": { \"foo\": 0, "
+ "\"baz\": 0.0 }, \"vector_aligned\": [ ], \"vector_of_structs\": [ { "
+ "\"x\": 1.0, \"y\": 2.0 } ], \"vector_of_tables\": [ ], "
+ "\"unspecified_length_vector\": [ ], \"unspecified_length_string\": "
+ "\"\", \"unspecified_length_vector_of_strings\": [ ] }",
+ aos::FlatbufferToJson(builder.AsFlatbufferSpan()));
+}
+
+// More completely covers our object API copying by comparing the flatbuffer
+// Pack() methods to our FromFlatbuffer() methods.
+TEST_F(StaticFlatbuffersTest, FlatbufferObjectTypeCoverage) {
+ VerifyJson<aos::testing::ConfigurationStatic>("{\n\n}");
+ std::string populated_config =
+ aos::util::ReadFileToStringOrDie(aos::testing::ArtifactPath(
+ "aos/flatbuffers/test_dir/type_coverage.json"));
+ Builder<aos::testing::ConfigurationStatic> json_builder =
+ aos::JsonToStaticFlatbuffer<aos::testing::ConfigurationStatic>(
+ populated_config);
+ aos::testing::ConfigurationT object_t;
+ json_builder->AsFlatbuffer().UnPackTo(&object_t);
+
+ Builder<aos::testing::ConfigurationStatic> from_object_static;
+ ASSERT_TRUE(from_object_static->FromFlatbuffer(object_t));
+ flatbuffers::FlatBufferBuilder fbb;
+ fbb.Finish(aos::testing::Configuration::Pack(fbb, &object_t));
+ aos::FlatbufferDetachedBuffer<aos::testing::Configuration> from_object_raw =
+ fbb.Release();
+ EXPECT_EQ(aos::FlatbufferToJson(from_object_raw, {.multi_line = true}),
+ aos::FlatbufferToJson(from_object_static, {.multi_line = true}));
+}
+
+// Tests that we can build code that uses the reflection types.
+TEST_F(StaticFlatbuffersTest, IncludeReflectionTypes) {
+ VerifyJson<::aos::testing::UseSchemaStatic>("{\n\n}");
+}
+
} // namespace aos::fbs::testing
diff --git a/aos/flatbuffers/static_vector.h b/aos/flatbuffers/static_vector.h
index 7349a8d..6133075 100644
--- a/aos/flatbuffers/static_vector.h
+++ b/aos/flatbuffers/static_vector.h
@@ -203,6 +203,11 @@
typename internal::InlineWrapper<T, kInline>::FlatbufferType;
using ConstFlatbufferType =
typename internal::InlineWrapper<T, kInline>::ConstFlatbufferType;
+ // FlatbufferObjectType corresponds to the type used by the flatbuffer
+ // "object" API (i.e. the FlatbufferT types).
+ // This type will be something unintelligble for inline types.
+ using FlatbufferObjectType =
+ typename internal::InlineWrapper<T, kInline>::FlatbufferObjectType;
// flatbuffers::Vector type that corresponds to this Vector.
typedef flatbuffers::Vector<FlatbufferType> Flatbuffer;
typedef const flatbuffers::Vector<ConstFlatbufferType> ConstFlatbuffer;
@@ -329,7 +334,70 @@
// we can allocate through reserve()).
// This is a deep copy, and will call FromFlatbuffer on any constituent
// objects.
- [[nodiscard]] bool FromFlatbuffer(ConstFlatbuffer *vector);
+ [[nodiscard]] bool FromFlatbuffer(ConstFlatbuffer *vector) {
+ return FromFlatbuffer(*CHECK_NOTNULL(vector));
+ }
+ [[nodiscard]] bool FromFlatbuffer(ConstFlatbuffer &vector);
+ // The remaining FromFlatbuffer() overloads are for when using the flatbuffer
+ // "object" API, which uses std::vector's for representing vectors.
+ [[nodiscard]] bool FromFlatbuffer(const std::vector<InlineType> &vector) {
+ static_assert(kInline);
+ return FromData(vector.data(), vector.size());
+ }
+ // Overload for vectors of bools, since the standard library may not use a
+ // full byte per vector element.
+ [[nodiscard]] bool FromFlatbuffer(const std::vector<bool> &vector) {
+ static_assert(kInline);
+ // We won't be able to do a clean memcpy because std::vector<bool> may be
+ // implemented using bit-packing.
+ return FromIterator(vector.cbegin(), vector.cend());
+ }
+ // Overload for non-inline types. Note that to avoid having this overload get
+ // resolved with inline types, we make FlatbufferObjectType != InlineType.
+ [[nodiscard]] bool FromFlatbuffer(
+ const std::vector<FlatbufferObjectType> &vector) {
+ static_assert(!kInline);
+ return FromNotInlineIterable(vector);
+ }
+
+ // Copies values from the provided data pointer into the vector, resizing the
+ // vector as needed to match. Returns false on failure (e.g., if the
+ // underlying allocator has insufficient space to perform the copy). Only
+ // works for inline data types.
+ [[nodiscard]] bool FromData(const InlineType *input_data, size_t input_size) {
+ static_assert(kInline);
+ if (!reserve(input_size)) {
+ return false;
+ }
+
+ // We will be overwriting the whole vector very shortly; there is no need to
+ // clear the buffer to zero.
+ resize_inline(input_size, SetZero::kNo);
+
+ memcpy(inline_data(), input_data, size() * sizeof(InlineType));
+ return true;
+ }
+
+ // Copies values from the provided iterators into the vector, resizing the
+ // vector as needed to match. Returns false on failure (e.g., if the
+ // underlying allocator has insufficient space to perform the copy). Only
+ // works for inline data types.
+ // Does not attempt any optimizations if the iterators meet the
+ // std::contiguous_iterator concept; instead, it simply copies each element
+ // out one-by-one.
+ template <typename Iterator>
+ [[nodiscard]] bool FromIterator(Iterator begin, Iterator end) {
+ static_assert(kInline);
+ resize(0);
+ for (Iterator it = begin; it != end; ++it) {
+ if (!reserve(size() + 1)) {
+ return false;
+ }
+ // Should never fail, due to the reserve() above.
+ CHECK(emplace_back(*it));
+ }
+ return true;
+ }
// Returns the element at the provided index. index must be less than size().
const T &at(size_t index) const {
@@ -569,29 +637,22 @@
}
// Implementation that handles copying from a flatbuffers::Vector of an inline
// data type.
- [[nodiscard]] bool FromInlineFlatbuffer(ConstFlatbuffer *vector) {
- if (!reserve(CHECK_NOTNULL(vector)->size())) {
- return false;
- }
-
- // We will be overwriting the whole vector very shortly; there is no need to
- // clear the buffer to zero.
- resize_inline(vector->size(), SetZero::kNo);
-
- memcpy(inline_data(), vector->Data(), size() * sizeof(InlineType));
- return true;
+ [[nodiscard]] bool FromInlineFlatbuffer(ConstFlatbuffer &vector) {
+ return FromData(reinterpret_cast<const InlineType *>(vector.Data()),
+ vector.size());
}
// Implementation that handles copying from a flatbuffers::Vector of a
// not-inline data type.
- [[nodiscard]] bool FromNotInlineFlatbuffer(const Flatbuffer *vector) {
- if (!reserve(vector->size())) {
+ template <typename Iterable>
+ [[nodiscard]] bool FromNotInlineIterable(const Iterable &vector) {
+ if (!reserve(vector.size())) {
return false;
}
// "Clear" the vector.
resize_not_inline(0);
- for (const typename T::Flatbuffer *entry : *vector) {
+ for (const auto &entry : vector) {
if (!CHECK_NOTNULL(emplace_back())->FromFlatbuffer(entry)) {
return false;
}
@@ -599,6 +660,10 @@
return true;
}
+ [[nodiscard]] bool FromNotInlineFlatbuffer(const Flatbuffer &vector) {
+ return FromNotInlineIterable(vector);
+ }
+
// In order to allow for easy partial template specialization, we use a
// non-member class to call FromInline/FromNotInlineFlatbuffer and
// resize_inline/resize_not_inline. There are not actually any great ways to
@@ -659,6 +724,7 @@
public:
typedef Vector<char, kStaticLength, true, 0, true> VectorType;
typedef flatbuffers::String Flatbuffer;
+ typedef std::string FlatbufferObjectType;
String(std::span<uint8_t> buffer, ResizeableObject *parent)
: VectorType(buffer, parent) {}
virtual ~String() {}
@@ -667,6 +733,10 @@
VectorType::resize_inline(string.size(), SetZero::kNo);
memcpy(VectorType::data(), string.data(), string.size());
}
+ using VectorType::FromFlatbuffer;
+ [[nodiscard]] bool FromFlatbuffer(const std::string &string) {
+ return VectorType::FromData(string.data(), string.size());
+ }
std::string_view string_view() const {
return std::string_view(VectorType::data(), VectorType::size());
}
@@ -690,12 +760,13 @@
typedef T ObjectType;
typedef flatbuffers::Offset<typename T::Flatbuffer> FlatbufferType;
typedef flatbuffers::Offset<typename T::Flatbuffer> ConstFlatbufferType;
+ typedef T::FlatbufferObjectType FlatbufferObjectType;
static_assert((T::kSize % T::kAlign) == 0);
static constexpr size_t kDataAlign = T::kAlign;
static constexpr size_t kDataSize = T::kSize;
template <typename StaticVector>
static bool FromFlatbuffer(
- StaticVector *to, const typename StaticVector::ConstFlatbuffer *from) {
+ StaticVector *to, const typename StaticVector::ConstFlatbuffer &from) {
return to->FromNotInlineFlatbuffer(from);
}
template <typename StaticVector>
@@ -712,11 +783,12 @@
typedef T ObjectType;
typedef T FlatbufferType;
typedef T ConstFlatbufferType;
+ typedef T *FlatbufferObjectType;
static constexpr size_t kDataAlign = alignof(T);
static constexpr size_t kDataSize = sizeof(T);
template <typename StaticVector>
static bool FromFlatbuffer(
- StaticVector *to, const typename StaticVector::ConstFlatbuffer *from) {
+ StaticVector *to, const typename StaticVector::ConstFlatbuffer &from) {
return to->FromInlineFlatbuffer(from);
}
template <typename StaticVector>
@@ -731,11 +803,12 @@
typedef uint8_t ObjectType;
typedef uint8_t FlatbufferType;
typedef uint8_t ConstFlatbufferType;
+ typedef uint8_t *FlatbufferObjectType;
static constexpr size_t kDataAlign = 1u;
static constexpr size_t kDataSize = 1u;
template <typename StaticVector>
static bool FromFlatbuffer(
- StaticVector *to, const typename StaticVector::ConstFlatbuffer *from) {
+ StaticVector *to, const typename StaticVector::ConstFlatbuffer &from) {
return to->FromInlineFlatbuffer(from);
}
template <typename StaticVector>
@@ -753,11 +826,12 @@
typedef T ObjectType;
typedef T *FlatbufferType;
typedef const T *ConstFlatbufferType;
+ typedef T *FlatbufferObjectType;
static constexpr size_t kDataAlign = alignof(T);
static constexpr size_t kDataSize = sizeof(T);
template <typename StaticVector>
static bool FromFlatbuffer(
- StaticVector *to, const typename StaticVector::ConstFlatbuffer *from) {
+ StaticVector *to, const typename StaticVector::ConstFlatbuffer &from) {
return to->FromInlineFlatbuffer(from);
}
template <typename StaticVector>
@@ -770,7 +844,7 @@
template <typename T, size_t kStaticLength, bool kInline, size_t kForceAlign,
bool kNullTerminate>
bool Vector<T, kStaticLength, kInline, kForceAlign,
- kNullTerminate>::FromFlatbuffer(ConstFlatbuffer *vector) {
+ kNullTerminate>::FromFlatbuffer(ConstFlatbuffer &vector) {
return internal::InlineWrapper<T, kInline>::FromFlatbuffer(this, vector);
}
diff --git a/aos/flatbuffers/test_dir/BUILD b/aos/flatbuffers/test_dir/BUILD
index 76f5fb4..a6275a5 100644
--- a/aos/flatbuffers/test_dir/BUILD
+++ b/aos/flatbuffers/test_dir/BUILD
@@ -1,6 +1,13 @@
load("//aos/flatbuffers:generate.bzl", "static_flatbuffer")
static_flatbuffer(
+ name = "include_reflection_fbs",
+ srcs = ["include_reflection.fbs"],
+ visibility = ["//visibility:public"],
+ deps = ["//aos/flatbuffers/reflection:reflection_fbs"],
+)
+
+static_flatbuffer(
name = "include_fbs",
srcs = ["include.fbs"],
visibility = ["//visibility:public"],
diff --git a/aos/flatbuffers/test_dir/include_reflection.fbs b/aos/flatbuffers/test_dir/include_reflection.fbs
new file mode 100644
index 0000000..7eda4f5
--- /dev/null
+++ b/aos/flatbuffers/test_dir/include_reflection.fbs
@@ -0,0 +1,9 @@
+include "reflection/reflection.fbs";
+
+namespace aos.testing;
+
+table UseSchema {
+ schema:reflection.Schema (id: 0);
+}
+
+root_type UseSchema;
diff --git a/aos/flatbuffers/test_dir/sample_test_static.h b/aos/flatbuffers/test_dir/sample_test_static.h
index a6362d7..57ac57a 100644
--- a/aos/flatbuffers/test_dir/sample_test_static.h
+++ b/aos/flatbuffers/test_dir/sample_test_static.h
@@ -14,6 +14,8 @@
public:
// The underlying "raw" flatbuffer type for this type.
typedef aos::fbs::testing::MinimallyAlignedTable Flatbuffer;
+ typedef flatbuffers::unique_ptr<Flatbuffer::NativeTableType>
+ FlatbufferObjectType;
// Returns this object as a flatbuffer type. This reference may not be valid
// following mutations to the underlying flatbuffer, due to how memory may get
// may get moved around.
@@ -135,15 +137,39 @@
// returning true on success.
// This is a deep copy, and will call FromFlatbuffer on any constituent
// objects.
- [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer &other) {
Clear();
- if (other->has_field()) {
- set_field(other->field());
+ if (other.has_field()) {
+ set_field(other.field());
}
return true;
}
+ // Equivalent to FromFlatbuffer(const Flatbuffer&); this overload is provided
+ // to ease implementation of the aos::fbs::Vector internals.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ return FromFlatbuffer(*CHECK_NOTNULL(other));
+ }
+
+ // Copies the contents of the provided flatbuffer into this flatbuffer,
+ // returning true on success.
+ // Because the Flatbuffer Object API does not provide any concept of an
+ // optionally populated scalar field, all scalar fields will be populated
+ // after a call to FromFlatbufferObject().
+ // This is a deep copy, and will call FromFlatbufferObject on
+ // any constituent objects.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer::NativeTableType &other) {
+ Clear();
+
+ set_field(other.field);
+
+ return true;
+ }
+ [[nodiscard]] bool FromFlatbuffer(
+ const flatbuffers::unique_ptr<Flatbuffer::NativeTableType> &other) {
+ return FromFlatbuffer(*other);
+ }
private:
// We need to provide a MoveConstructor to allow this table to be
@@ -168,6 +194,8 @@
public:
// The underlying "raw" flatbuffer type for this type.
typedef aos::fbs::testing::SubTable Flatbuffer;
+ typedef flatbuffers::unique_ptr<Flatbuffer::NativeTableType>
+ FlatbufferObjectType;
// Returns this object as a flatbuffer type. This reference may not be valid
// following mutations to the underlying flatbuffer, due to how memory may get
// may get moved around.
@@ -314,19 +342,45 @@
// returning true on success.
// This is a deep copy, and will call FromFlatbuffer on any constituent
// objects.
- [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer &other) {
Clear();
- if (other->has_baz()) {
- set_baz(other->baz());
+ if (other.has_baz()) {
+ set_baz(other.baz());
}
- if (other->has_foo()) {
- set_foo(other->foo());
+ if (other.has_foo()) {
+ set_foo(other.foo());
}
return true;
}
+ // Equivalent to FromFlatbuffer(const Flatbuffer&); this overload is provided
+ // to ease implementation of the aos::fbs::Vector internals.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ return FromFlatbuffer(*CHECK_NOTNULL(other));
+ }
+
+ // Copies the contents of the provided flatbuffer into this flatbuffer,
+ // returning true on success.
+ // Because the Flatbuffer Object API does not provide any concept of an
+ // optionally populated scalar field, all scalar fields will be populated
+ // after a call to FromFlatbufferObject().
+ // This is a deep copy, and will call FromFlatbufferObject on
+ // any constituent objects.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer::NativeTableType &other) {
+ Clear();
+
+ set_baz(other.baz);
+
+ set_foo(other.foo);
+
+ return true;
+ }
+ [[nodiscard]] bool FromFlatbuffer(
+ const flatbuffers::unique_ptr<Flatbuffer::NativeTableType> &other) {
+ return FromFlatbuffer(*other);
+ }
private:
// We need to provide a MoveConstructor to allow this table to be
@@ -354,6 +408,8 @@
public:
// The underlying "raw" flatbuffer type for this type.
typedef aos::fbs::testing::TestTable Flatbuffer;
+ typedef flatbuffers::unique_ptr<Flatbuffer::NativeTableType>
+ FlatbufferObjectType;
// Returns this object as a flatbuffer type. This reference may not be valid
// following mutations to the underlying flatbuffer, due to how memory may get
// may get moved around.
@@ -1060,109 +1116,108 @@
// returning true on success.
// This is a deep copy, and will call FromFlatbuffer on any constituent
// objects.
- [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer &other) {
Clear();
- if (other->has_included_table()) {
+ if (other.has_included_table()) {
if (!CHECK_NOTNULL(add_included_table())
- ->FromFlatbuffer(other->included_table())) {
+ ->FromFlatbuffer(other.included_table())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_scalar()) {
- set_scalar(other->scalar());
+ if (other.has_scalar()) {
+ set_scalar(other.scalar());
}
- if (other->has_string()) {
- if (!CHECK_NOTNULL(add_string())->FromFlatbuffer(other->string())) {
+ if (other.has_string()) {
+ if (!CHECK_NOTNULL(add_string())->FromFlatbuffer(other.string())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_substruct()) {
- set_substruct(*other->substruct());
+ if (other.has_substruct()) {
+ set_substruct(*other.substruct());
}
- if (other->has_subtable()) {
- if (!CHECK_NOTNULL(add_subtable())->FromFlatbuffer(other->subtable())) {
+ if (other.has_subtable()) {
+ if (!CHECK_NOTNULL(add_subtable())->FromFlatbuffer(other.subtable())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_unspecified_length_string()) {
+ if (other.has_unspecified_length_string()) {
if (!CHECK_NOTNULL(add_unspecified_length_string())
- ->FromFlatbuffer(other->unspecified_length_string())) {
+ ->FromFlatbuffer(other.unspecified_length_string())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_unspecified_length_vector()) {
+ if (other.has_unspecified_length_vector()) {
if (!CHECK_NOTNULL(add_unspecified_length_vector())
- ->FromFlatbuffer(other->unspecified_length_vector())) {
+ ->FromFlatbuffer(other.unspecified_length_vector())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_unspecified_length_vector_of_strings()) {
+ if (other.has_unspecified_length_vector_of_strings()) {
if (!CHECK_NOTNULL(add_unspecified_length_vector_of_strings())
- ->FromFlatbuffer(
- other->unspecified_length_vector_of_strings())) {
+ ->FromFlatbuffer(other.unspecified_length_vector_of_strings())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_vector_aligned()) {
+ if (other.has_vector_aligned()) {
if (!CHECK_NOTNULL(add_vector_aligned())
- ->FromFlatbuffer(other->vector_aligned())) {
+ ->FromFlatbuffer(other.vector_aligned())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_vector_of_scalars()) {
+ if (other.has_vector_of_scalars()) {
if (!CHECK_NOTNULL(add_vector_of_scalars())
- ->FromFlatbuffer(other->vector_of_scalars())) {
+ ->FromFlatbuffer(other.vector_of_scalars())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_vector_of_strings()) {
+ if (other.has_vector_of_strings()) {
if (!CHECK_NOTNULL(add_vector_of_strings())
- ->FromFlatbuffer(other->vector_of_strings())) {
+ ->FromFlatbuffer(other.vector_of_strings())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_vector_of_structs()) {
+ if (other.has_vector_of_structs()) {
if (!CHECK_NOTNULL(add_vector_of_structs())
- ->FromFlatbuffer(other->vector_of_structs())) {
+ ->FromFlatbuffer(other.vector_of_structs())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
}
}
- if (other->has_vector_of_tables()) {
+ if (other.has_vector_of_tables()) {
if (!CHECK_NOTNULL(add_vector_of_tables())
- ->FromFlatbuffer(other->vector_of_tables())) {
+ ->FromFlatbuffer(other.vector_of_tables())) {
// Fail if we were unable to copy (e.g., if we tried to copy in a long
// vector and do not have the space for it).
return false;
@@ -1171,6 +1226,140 @@
return true;
}
+ // Equivalent to FromFlatbuffer(const Flatbuffer&); this overload is provided
+ // to ease implementation of the aos::fbs::Vector internals.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer *other) {
+ return FromFlatbuffer(*CHECK_NOTNULL(other));
+ }
+
+ // Copies the contents of the provided flatbuffer into this flatbuffer,
+ // returning true on success.
+ // Because the Flatbuffer Object API does not provide any concept of an
+ // optionally populated scalar field, all scalar fields will be populated
+ // after a call to FromFlatbufferObject().
+ // This is a deep copy, and will call FromFlatbufferObject on
+ // any constituent objects.
+ [[nodiscard]] bool FromFlatbuffer(const Flatbuffer::NativeTableType &other) {
+ Clear();
+
+ if (other.included_table) {
+ if (!CHECK_NOTNULL(add_included_table())
+ ->FromFlatbuffer(*other.included_table)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+ }
+
+ set_scalar(other.scalar);
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_string())->FromFlatbuffer(other.string)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ if (other.substruct) {
+ set_substruct(*other.substruct);
+ }
+
+ if (other.subtable) {
+ if (!CHECK_NOTNULL(add_subtable())->FromFlatbuffer(*other.subtable)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_unspecified_length_string())
+ ->FromFlatbuffer(other.unspecified_length_string)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_unspecified_length_vector())
+ ->FromFlatbuffer(other.unspecified_length_vector)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_unspecified_length_vector_of_strings())
+ ->FromFlatbuffer(other.unspecified_length_vector_of_strings)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_vector_aligned())
+ ->FromFlatbuffer(other.vector_aligned)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_vector_of_scalars())
+ ->FromFlatbuffer(other.vector_of_scalars)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_vector_of_strings())
+ ->FromFlatbuffer(other.vector_of_strings)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_vector_of_structs())
+ ->FromFlatbuffer(other.vector_of_structs)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ // Unconditionally copy strings/vectors, even if it will just end up
+ // being 0-length (this maintains consistency with the flatbuffer Pack()
+ // behavior).
+ if (!CHECK_NOTNULL(add_vector_of_tables())
+ ->FromFlatbuffer(other.vector_of_tables)) {
+ // Fail if we were unable to copy (e.g., if we tried to copy in a long
+ // vector and do not have the space for it).
+ return false;
+ }
+
+ return true;
+ }
+ [[nodiscard]] bool FromFlatbuffer(
+ const flatbuffers::unique_ptr<Flatbuffer::NativeTableType> &other) {
+ return FromFlatbuffer(*other);
+ }
private:
// We need to provide a MoveConstructor to allow this table to be
diff --git a/aos/json_to_flatbuffer.h b/aos/json_to_flatbuffer.h
index 6ef3544..deafaa7 100644
--- a/aos/json_to_flatbuffer.h
+++ b/aos/json_to_flatbuffer.h
@@ -75,6 +75,12 @@
Flatbuffer<T>::MiniReflectTypeTable(), json_options);
}
+template <typename T, typename Enable = T::Flatbuffer>
+inline ::std::string FlatbufferToJson(const fbs::Builder<T> &flatbuffer,
+ JsonOptions json_options = {}) {
+ return FlatbufferToJson(flatbuffer.AsFlatbufferSpan(), json_options);
+}
+
// Converts a flatbuffer::Table to JSON.
template <typename T>
typename std::enable_if<
diff --git a/aos/network/sctp_lib.cc b/aos/network/sctp_lib.cc
index 829ae67..cf50ad6 100644
--- a/aos/network/sctp_lib.cc
+++ b/aos/network/sctp_lib.cc
@@ -4,6 +4,7 @@
#include <linux/sctp.h>
#include <net/if.h>
#include <netdb.h>
+#include <netinet/ip.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -26,6 +27,25 @@
DEFINE_bool(disable_ipv6, false, "disable ipv6");
DEFINE_int32(rmem, 0, "If nonzero, set rmem to this size.");
+// The Type of Service.
+// https://www.tucny.com/Home/dscp-tos
+//
+// We want to set the highest precedence (i.e. critical) with minimal delay. We
+// also want to be able to stuff the packets into bucket 0 for queue
+// disciplining. Experiments show that 176 works for this. Other values (e.g.
+// DSCP class EF) cannot be stuffed into bucket 0 (for unknown reasons).
+//
+// Note that the two least significant bits are reserved and should always set
+// to zero. Those two bits are the "Explicit Congestion Notification" bits. They
+// are controlled by the IP stack itself (and used by the router). We don't
+// control that via the TOS value we set here.
+DEFINE_int32(
+ sctp_tos, 176,
+ "The Type-Of-Service value to use. Defaults to a critical priority. "
+ "Always set values here whose two least significant bits are set to zero. "
+ "When using tcpdump, the `tos` field may show the least significant two "
+ "bits set to something other than zero.");
+
namespace aos::message_bridge {
namespace {
@@ -272,6 +292,13 @@
LOG(INFO) << "socket(" << Family(sockaddr_local)
<< ", SOCK_SEQPACKET, IPPROTOSCTP) = " << fd_;
{
+ // Set up Type-Of-Service.
+ //
+ // See comments for the --sctp_tos flag for more information.
+ int tos = IPTOS_DSCP(FLAGS_sctp_tos);
+ PCHECK(setsockopt(fd_, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)) == 0);
+ }
+ {
// Per https://tools.ietf.org/html/rfc6458
// Setting this to !0 allows event notifications to be interleaved
// with data if enabled. This typically only matters during congestion.
diff --git a/aos/starter/starterd_lib.cc b/aos/starter/starterd_lib.cc
index 95210c0..38d519d 100644
--- a/aos/starter/starterd_lib.cc
+++ b/aos/starter/starterd_lib.cc
@@ -19,6 +19,7 @@
DEFINE_uint32(queue_initialization_threads, 0,
"Number of threads to spin up to initialize the queue. 0 means "
"use the main thread.");
+DECLARE_bool(enable_ftrace);
namespace aos::starter {
@@ -214,6 +215,11 @@
if (info.ssi_signo == SIGCHLD) {
// SIGCHLD messages can be collapsed if multiple are received, so all
// applications must check their status.
+ if (FLAGS_enable_ftrace) {
+ ftrace_.FormatMessage("SIGCHLD");
+ ftrace_.TurnOffOrDie();
+ }
+
for (auto iter = applications_.begin(); iter != applications_.end();) {
if (iter->second.MaybeHandleSignal()) {
iter = applications_.erase(iter);
diff --git a/aos/starter/starterd_lib.h b/aos/starter/starterd_lib.h
index 3779c84..1ffc782 100644
--- a/aos/starter/starterd_lib.h
+++ b/aos/starter/starterd_lib.h
@@ -77,6 +77,8 @@
aos::PhasedLoopHandler *status_timer_;
aos::TimerHandler *cleanup_timer_;
+ aos::Ftrace ftrace_;
+
int status_count_ = 0;
const int max_status_count_;
diff --git a/aos/starter/subprocess.cc b/aos/starter/subprocess.cc
index 9606adc..d677922 100644
--- a/aos/starter/subprocess.cc
+++ b/aos/starter/subprocess.cc
@@ -266,6 +266,8 @@
if (application->has_memory_limit() && application->memory_limit() > 0) {
SetMemoryLimit(application->memory_limit());
}
+
+ set_stop_grace_period(std::chrono::nanoseconds(application->stop_time()));
}
void Application::DoStart() {
@@ -496,8 +498,7 @@
// Watchdog timer to SIGKILL application if it is still running 1 second
// after SIGINT
- stop_timer_->Schedule(event_loop_->monotonic_now() +
- std::chrono::seconds(1));
+ stop_timer_->Schedule(event_loop_->monotonic_now() + stop_grace_period_);
queue_restart_ = restart;
OnChange();
break;
diff --git a/aos/starter/subprocess.h b/aos/starter/subprocess.h
index ca7ef9d..eb36874 100644
--- a/aos/starter/subprocess.h
+++ b/aos/starter/subprocess.h
@@ -139,6 +139,14 @@
void set_capture_stderr(bool capture);
void set_run_as_sudo(bool value) { run_as_sudo_ = value; }
+ // Sets the time for a process to stop gracefully. If an application is asked
+ // to stop, but doesn't stop within the specified time limit, then it is
+ // forcefully killed. Defaults to 1 second unless overridden by the
+ // aos::Application instance in the constructor.
+ void set_stop_grace_period(std::chrono::nanoseconds stop_grace_period) {
+ stop_grace_period_ = stop_grace_period;
+ }
+
bool autostart() const { return autostart_; }
bool autorestart() const { return autorestart_; }
@@ -222,6 +230,7 @@
std::optional<uid_t> user_;
std::optional<gid_t> group_;
bool run_as_sudo_ = false;
+ std::chrono::nanoseconds stop_grace_period_ = std::chrono::seconds(1);
bool capture_stdout_ = false;
PipePair stdout_pipes_;
diff --git a/aos/starter/subprocess_reliable_test.cc b/aos/starter/subprocess_reliable_test.cc
index 0460bc3..701de11 100644
--- a/aos/starter/subprocess_reliable_test.cc
+++ b/aos/starter/subprocess_reliable_test.cc
@@ -3,6 +3,7 @@
#include <filesystem>
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "aos/events/shm_event_loop.h"
@@ -124,4 +125,55 @@
ASSERT_TRUE(std::filesystem::exists(shutdown_signal_file));
}
+// Validates that a process that is known to take a while to stop can shut down
+// gracefully without being killed.
+TEST(SubprocessTest, CanSlowlyStopGracefully) {
+ const std::string config_file =
+ ::aos::testing::ArtifactPath("aos/events/pingpong_config.json");
+ aos::FlatbufferDetachedBuffer<aos::Configuration> config =
+ aos::configuration::ReadConfig(config_file);
+ aos::ShmEventLoop event_loop(&config.message());
+
+ // Use a file to signal that the subprocess has started up properly and that
+ // the exit handler has been installed. Otherwise we risk killing the process
+ // uncleanly before the signal handler got installed.
+ auto signal_dir = std::filesystem::path(aos::testing::TestTmpDir()) /
+ "slow_death_startup_file_signals";
+ ASSERT_TRUE(std::filesystem::create_directory(signal_dir));
+ auto startup_signal_file = signal_dir / "startup";
+
+ // Create an application that should never get killed automatically. It should
+ // have plenty of time to shut down on its own. In this case, we use 2 seconds
+ // to mean "plenty of time".
+ auto application = std::make_unique<Application>("/bin/bash", "/bin/bash",
+ &event_loop, [] {});
+ application->set_args(
+ {"-c",
+ absl::StrCat(
+ "trap 'echo got int; sleep 2; echo shutting down; exit 0' SIGINT; "
+ "while true; do sleep 0.1; touch ",
+ startup_signal_file.string(), "; done;")});
+ application->set_capture_stdout(true);
+ application->set_stop_grace_period(std::chrono::seconds(999));
+ application->AddOnChange([&] {
+ if (application->status() == aos::starter::State::STOPPED) {
+ event_loop.Exit();
+ }
+ });
+ application->Start();
+ event_loop
+ .AddTimer([&] {
+ if (std::filesystem::exists(startup_signal_file)) {
+ // Now that the subprocess has properly started up, let's kill it.
+ application->Stop();
+ }
+ })
+ ->Schedule(event_loop.monotonic_now(), std::chrono::milliseconds(100));
+ event_loop.Run();
+
+ EXPECT_EQ(application->exit_code(), 0);
+ EXPECT_THAT(application->GetStdout(), ::testing::HasSubstr("got int"));
+ EXPECT_THAT(application->GetStdout(), ::testing::HasSubstr("shutting down"));
+}
+
} // namespace aos::starter::testing
diff --git a/aos/time/time.cc b/aos/time/time.cc
index 6a25aa9..e75fe45 100644
--- a/aos/time/time.cc
+++ b/aos/time/time.cc
@@ -6,6 +6,7 @@
#include <cstring>
#include <ctime>
#include <iomanip>
+#include <sstream>
#ifdef __linux__
@@ -79,6 +80,18 @@
return stream;
}
+std::string ToString(const aos::monotonic_clock::time_point &now) {
+ std::ostringstream stream;
+ stream << now;
+ return stream.str();
+}
+
+std::string ToString(const aos::realtime_clock::time_point &now) {
+ std::ostringstream stream;
+ stream << now;
+ return stream.str();
+}
+
#ifdef __linux__
std::optional<monotonic_clock::time_point> monotonic_clock::FromString(
const std::string_view now) {
@@ -170,6 +183,16 @@
: std::chrono::duration_cast<std::chrono::seconds>(
now.time_since_epoch());
+ // We can run into some corner cases where the seconds value is large enough
+ // to cause the conversion to nanoseconds to overflow. That is undefined
+ // behaviour so we prevent it with this check here.
+ if (int64_t result;
+ __builtin_mul_overflow(seconds.count(), 1'000'000'000, &result)) {
+ stream << "(unrepresentable realtime " << now.time_since_epoch().count()
+ << ")";
+ return stream;
+ }
+
std::time_t seconds_t = seconds.count();
stream << std::put_time(localtime_r(&seconds_t, &tm), "%Y-%m-%d_%H-%M-%S.")
<< std::setfill('0') << std::setw(9)
diff --git a/aos/time/time.h b/aos/time/time.h
index 1a5cbd1..8462625 100644
--- a/aos/time/time.h
+++ b/aos/time/time.h
@@ -81,6 +81,9 @@
std::ostream &operator<<(std::ostream &stream,
const aos::realtime_clock::time_point &now);
+std::string ToString(const aos::monotonic_clock::time_point &now);
+std::string ToString(const aos::realtime_clock::time_point &now);
+
namespace time {
#ifdef __linux__
diff --git a/aos/time/time_test.cc b/aos/time/time_test.cc
index 63a145b..97116b0 100644
--- a/aos/time/time_test.cc
+++ b/aos/time/time_test.cc
@@ -208,8 +208,9 @@
std::stringstream s;
s << t;
- EXPECT_EQ(s.str(), "1677-09-21_00-12-43.145224192");
- EXPECT_EQ(realtime_clock::FromString(s.str()).value(), t);
+ // min_time happens to be unrepresentable because of rounding and signed
+ // integer overflow.
+ EXPECT_EQ(s.str(), "(unrepresentable realtime -9223372036854775808)");
}
{
@@ -224,4 +225,12 @@
}
}
+// Test that ToString works for monotonic and realtime time points.
+TEST(TimeTest, ToStringTimePoints) {
+ EXPECT_EQ(ToString(realtime_clock::epoch() + std::chrono::hours(5 * 24) +
+ std::chrono::seconds(11) + std::chrono::milliseconds(5)),
+ "1970-01-06_00-00-11.005000000");
+ EXPECT_EQ(ToString(monotonic_clock::min_time), "-9223372036.854775808sec");
+}
+
} // namespace aos::time::testing
diff --git a/aos/util/mcap_logger_test.cc b/aos/util/mcap_logger_test.cc
index c6febf9..3684e93 100644
--- a/aos/util/mcap_logger_test.cc
+++ b/aos/util/mcap_logger_test.cc
@@ -81,6 +81,20 @@
"values": {
"items": {
"properties": {
+ "attributes": {
+ "items": {
+ "properties": {
+ "key": {
+ "type": "string"
+ },
+ "value": {
+ "type": "string"
+ }
+ },
+ "type": "object"
+ },
+ "type": "array"
+ },
"documentation": {
"items": {
"type": "string"
diff --git a/aos/uuid.h b/aos/uuid.h
index 8dd93d4..a2cf8ae 100644
--- a/aos/uuid.h
+++ b/aos/uuid.h
@@ -8,6 +8,7 @@
#include "absl/types/span.h"
#include "flatbuffers/flatbuffers.h"
+#include "glog/logging.h"
namespace aos {
@@ -66,6 +67,11 @@
flatbuffers::Offset<flatbuffers::Vector<uint8_t>> PackVector(
flatbuffers::FlatBufferBuilder *fbb) const;
+ template <typename T>
+ void PackStaticVector(T *static_vector) const {
+ CHECK(static_vector->FromData(data_.data(), data_.size()));
+ }
+
// Returns a human-readable string representing this UUID.
//
// This is done without any memory allocation, which means it's returned in a
diff --git a/documentation/aos/docs/flatbuffers.md b/documentation/aos/docs/flatbuffers.md
index 132348d..9c82ee3 100644
--- a/documentation/aos/docs/flatbuffers.md
+++ b/documentation/aos/docs/flatbuffers.md
@@ -157,13 +157,30 @@
type using the regular generated flatbuffer API and a `FromFlatbuffer()` method
which attempts to copy the specified flatbuffer into the current object.
+The `FromFlatbuffer()` method works on both the "raw" flatbuffer type, as well
+as on the [Flatbuffer Object
+API](https://flatbuffers.dev/flatbuffers_guide_use_cpp.html) (i.e. the
+`FlatbufferT` types). When copying
+flatbuffers from the object-based API, we apply the same semantics that that the
+`Pack()` method does in the raw flatbuffer type. Namely, all non-table fields
+will be set:
+
+ * Scalar fields are always populated, even if their value is equal to the
+ default.
+ * Vectors are set to zero-length vectors if there is no data in the vector.
+ * Strings are set to the empty string if there is no data in the string.
+
+These limitations are a consequence of how flatbuffers are represented in the
+object API, and is not an issue when copying from regular flatbuffer types.
+For copying from raw flatbuffer objects (which is what most existing code
+uses), these caveats do not apply, and there is no loss of information.
+
### Sample Usage
The below example constructs a table of the above example `TestTable`:
```cpp
-aos::FixedAllocator allocator(TestTableStatic::kUnalignedBufferSize);
-Builder<TestTableStatic> builder(&allocator);
+Builder<TestTableStatic> builder;
TestTableStatic *object = builder.get();
object->set_scalar(123);
{
@@ -436,10 +453,24 @@
space allocated for the vector; returns false on failure (e.g., if you are in
a fixed-size allocator that does not support increasing the size past a
certain point).
-* `bool FromFlatbuffer(const flatbuffers::Vector<>*)`: Attempts to copy an
+* `bool FromFlatbuffer(const flatbuffers::Vector<>&)`: Attempts to copy an
existing vector into this `Vector`. This may attempt to call `reserve()`
if the new vector is longer than `capacity()`. If the copy fails for
any reason, returns `false`.
+* `bool FromFlatbuffer(const std::vector<>&)`: Attempts to copy an
+ existing vector into this `Vector`. This may attempt to call `reserve()`
+ if the new vector is longer than `capacity()`. If the copy fails for
+ any reason, returns `false`. This is called "`FromFlatbuffer`" because
+ the [Flatbuffer Object
+ API](https://flatbuffers.dev/flatbuffers_guide_use_cpp.html) uses
+ `std::vector<>` to represent vectors.
+* `bool FromData(const T*, size_t)`: Attempts to copy a contiguous set of data
+ from the provided pointer. Only applies to inline types. This may attempt to
+ call `reserve()`, and if the call fails, it returns `false`.
+* `bool FromIterator(It begin, It end)`: Attempts to copy data from [begin, end)
+ into the vector. Does not assume that the data is stored contiguously in
+ memory. Only applies to inline types. This may attempt to
+ call `reserve()`, and if the call fails, it returns `false`.
#### Managing Resizing of Vectors
@@ -510,12 +541,25 @@
# upgraded to static_flatbuffer rules.
static_flatbuffer(
name = "test_message_fbs",
- src = "test_message.fbs",
+ srcs = ["test_message.fbs"],
)
```
+Then you must update the `#include` to use a `test_message_static.h` instead of
+the standard `test_message_generated.h` (the `_static.h` will include the
+`_generated.h` itself). Any C++ code can then be updated, noting that any
+AOS Senders that need to use the new API need to have their definitions updated
+to use the `TestMessageStatic` and must call `MakeStaticBuilder` instead of
+`MakeBuilder`. There is currently no support for using static flatbuffers with
+the AOS Fetcher or Watcher interfaces, as these only present immutable objects
+and so do not benefit from the API additions (and attempting to convert them to
+the new API would require additional overhead associated with copying the
+serialized flatbuffer into the correct format).
+
Before:
```cpp
+#include "aos/events/test_message_generated.h"
+...
aos::Sender<TestMessage> sender = loop1->MakeSender<TestMessage>("/test");
loop->OnRun([&]() {
@@ -528,6 +572,8 @@
After:
```cpp
+#include "aos/events/test_message_static.h"
+...
aos::Sender<TestMessageStatic> sender =
loop1->MakeSender<TestMessageStatic>("/test");
diff --git a/frc971/can_logger/can_logger.cc b/frc971/can_logger/can_logger.cc
index d7c2df7..cfc3dd8 100644
--- a/frc971/can_logger/can_logger.cc
+++ b/frc971/can_logger/can_logger.cc
@@ -5,10 +5,11 @@
CanLogger::CanLogger(aos::ShmEventLoop *event_loop,
std::string_view channel_name,
std::string_view interface_name)
- : fd_(socket(PF_CAN, SOCK_RAW | SOCK_NONBLOCK, CAN_RAW)),
- frames_sender_(event_loop->MakeSender<CanFrame>(channel_name)) {
+ : shm_event_loop_(event_loop),
+ fd_(socket(PF_CAN, SOCK_RAW | SOCK_NONBLOCK, CAN_RAW)),
+ frames_sender_(shm_event_loop_->MakeSender<CanFrame>(channel_name)) {
// TOOD(max): Figure out a proper priority
- event_loop->SetRuntimeRealtimePriority(10);
+ shm_event_loop_->SetRuntimeRealtimePriority(10);
struct ifreq ifr;
strcpy(ifr.ifr_name, interface_name.data());
PCHECK(ioctl(fd_.get(), SIOCGIFINDEX, &ifr) == 0)
@@ -34,7 +35,7 @@
CHECK_EQ(opt_size, sizeof(recieve_buffer_size));
VLOG(0) << "CAN recieve bufffer is " << recieve_buffer_size << " bytes large";
- event_loop->epoll()->OnReadable(fd_.get(), [this]() { Poll(); });
+ shm_event_loop_->epoll()->OnReadable(fd_.get(), [this]() { Poll(); });
}
void CanLogger::Poll() {
diff --git a/frc971/can_logger/can_logger.h b/frc971/can_logger/can_logger.h
index a144265..6bad877 100644
--- a/frc971/can_logger/can_logger.h
+++ b/frc971/can_logger/can_logger.h
@@ -33,6 +33,8 @@
CanLogger(const CanLogger &) = delete;
CanLogger &operator=(const CanLogger &) = delete;
+ ~CanLogger() { shm_event_loop_->epoll()->DeleteFd(fd_.get()); }
+
private:
void Poll();
@@ -40,6 +42,7 @@
// Returns true if successful and false if the recieve buffer is empty.
bool ReadFrame();
+ aos::ShmEventLoop *shm_event_loop_;
aos::ScopedFD fd_;
aos::Sender<CanFrame> frames_sender_;
};
diff --git a/scouting/scouting_test.cy.js b/scouting/scouting_test.cy.js
index 7d5d75b..691d8fc 100644
--- a/scouting/scouting_test.cy.js
+++ b/scouting/scouting_test.cy.js
@@ -84,14 +84,14 @@
cy.get('[type="radio"]').first().check();
clickButton('Start Match');
- // Pick and Place Cone in Auto.
- clickButton('CONE');
- clickButton('HIGH');
+ // Pick and Place Note in Auto.
+ clickButton('NOTE');
+ clickButton('AMP');
// Pick and Place Cube in Teleop.
clickButton('Start Teleop');
- clickButton('CUBE');
- clickButton('LOW');
+ clickButton('NOTE');
+ clickButton('AMP AMPLIFIED');
// Robot dead and revive.
clickButton('DEAD');
@@ -99,19 +99,19 @@
// Endgame.
clickButton('Endgame');
- cy.contains(/Docked & Engaged/).click();
+ cy.contains(/Harmony/).click();
clickButton('End Match');
headerShouldBe(teamNumber + ' Review and Submit ');
cy.get('#review_data li')
.eq(0)
.should('have.text', ' Started match at position 1 ');
- cy.get('#review_data li').eq(1).should('have.text', ' Picked up kCone ');
+ cy.get('#review_data li').eq(1).should('have.text', 'Picked up Note');
cy.get('#review_data li')
.last()
.should(
'have.text',
- ' Ended Match; docked: false, engaged: true, attempted to dock and engage: false '
+ ' Ended Match; park: false, onStage: false, harmony: true, trapNote: false '
);
clickButton('Submit');
@@ -264,8 +264,8 @@
cy.get('[type="radio"]').first().check();
clickButton('Start Match');
- // Pick up cone.
- clickButton('CONE');
+ // Pick up note.
+ clickButton('NOTE');
// Undo that pick up.
clickButton('UNDO');
@@ -274,8 +274,8 @@
headerShouldBe('3990 Pickup ');
// Check the same thing but for undoing place.
- clickButton('CUBE');
- clickButton('MID');
+ clickButton('NOTE');
+ clickButton('AMP');
clickButton('UNDO');
headerShouldBe('3990 Place ');
});
diff --git a/scouting/webserver/requests/messages/submit_2024_actions.fbs b/scouting/webserver/requests/messages/submit_2024_actions.fbs
index 5cb3cbe..61e36bc 100644
--- a/scouting/webserver/requests/messages/submit_2024_actions.fbs
+++ b/scouting/webserver/requests/messages/submit_2024_actions.fbs
@@ -15,7 +15,9 @@
mobility:bool (id:0);
}
-table PenaltyAction {}
+table PenaltyAction {
+ penalties: int (id:0);
+}
table PickupNoteAction {
auto:bool (id:0);
diff --git a/scouting/webserver/requests/requests.go b/scouting/webserver/requests/requests.go
index 75b438b..31ad4e3 100644
--- a/scouting/webserver/requests/requests.go
+++ b/scouting/webserver/requests/requests.go
@@ -199,8 +199,7 @@
}
func (handler requestAllMatchesHandler) teamHasBeenDataScouted(key MatchAssemblyKey, teamNumber string) (bool, error) {
- // TODO change this to reference 2024 stats
- stats, err := handler.db.ReturnStats2023ForTeam(
+ stats, err := handler.db.ReturnStats2024ForTeam(
teamNumber, key.MatchNumber, key.SetNumber, key.CompLevel, false)
if err != nil {
return false, err
@@ -480,7 +479,7 @@
} else if action_type == submit_2024_actions.ActionTypePenaltyAction {
var penaltyAction submit_2024_actions.PenaltyAction
penaltyAction.Init(actionTable.Bytes, actionTable.Pos)
- stat.Penalties += 1
+ stat.Penalties += penaltyAction.Penalties()
} else if action_type == submit_2024_actions.ActionTypePickupNoteAction {
var pick_up_action submit_2024_actions.PickupNoteAction
@@ -1165,12 +1164,12 @@
err = handler.db.AddToStats2024(stats)
if err != nil {
- respondWithError(w, http.StatusInternalServerError, fmt.Sprint("Failed to submit stats: ", stats, ": ", err))
+ respondWithError(w, http.StatusInternalServerError, fmt.Sprint("Failed to submit stats2024: ", stats, ": ", err))
return
}
builder := flatbuffers.NewBuilder(50 * 1024)
- builder.Finish((&SubmitActionsResponseT{}).Pack(builder))
+ builder.Finish((&Submit2024ActionsResponseT{}).Pack(builder))
w.Write(builder.FinishedBytes())
}
diff --git a/scouting/webserver/requests/requests_test.go b/scouting/webserver/requests/requests_test.go
index 67244d3..eb5e904 100644
--- a/scouting/webserver/requests/requests_test.go
+++ b/scouting/webserver/requests/requests_test.go
@@ -131,30 +131,22 @@
},
},
// Pretend that we have some data scouting data.
- stats2023: []db.Stats2023{
+ stats2024: []db.Stats2024{
{
- TeamNumber: "5", MatchNumber: 1, SetNumber: 1,
- CompLevel: "qm", StartingQuadrant: 3, LowCubesAuto: 10,
- MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 0,
- LowConesAuto: 1, MiddleConesAuto: 2, HighConesAuto: 1,
- ConesDroppedAuto: 0, LowCubes: 1, MiddleCubes: 1,
- HighCubes: 2, CubesDropped: 1, LowCones: 1,
- MiddleCones: 2, HighCones: 0, ConesDropped: 1, SuperchargedPieces: 0,
- AvgCycle: 34, Mobility: false, DockedAuto: true, EngagedAuto: true,
- BalanceAttemptAuto: false, Docked: false, Engaged: false,
- BalanceAttempt: false, CollectedBy: "alex",
+ PreScouting: false, TeamNumber: "5",
+ MatchNumber: 1, SetNumber: 1, CompLevel: "qm", StartingQuadrant: 3,
+ SpeakerAuto: 2, AmpAuto: 4, NotesDroppedAuto: 1, MobilityAuto: true,
+ Speaker: 0, Amp: 1, SpeakerAmplified: 2, AmpAmplified: 1,
+ NotesDropped: 0, Penalties: 01, TrapNote: true, AvgCycle: 233,
+ Park: false, OnStage: true, Harmony: false, CollectedBy: "alex",
},
{
- TeamNumber: "973", MatchNumber: 3, SetNumber: 1,
- CompLevel: "qm", StartingQuadrant: 1, LowCubesAuto: 0,
- MiddleCubesAuto: 1, HighCubesAuto: 1, CubesDroppedAuto: 2,
- LowConesAuto: 0, MiddleConesAuto: 0, HighConesAuto: 0,
- ConesDroppedAuto: 1, LowCubes: 0, MiddleCubes: 0,
- HighCubes: 1, CubesDropped: 0, LowCones: 0,
- MiddleCones: 2, HighCones: 1, ConesDropped: 1, SuperchargedPieces: 0,
- AvgCycle: 53, Mobility: true, DockedAuto: true, EngagedAuto: false,
- BalanceAttemptAuto: false, Docked: false, Engaged: false,
- BalanceAttempt: true, CollectedBy: "bob",
+ PreScouting: false, TeamNumber: "973",
+ MatchNumber: 3, SetNumber: 1, CompLevel: "qm", StartingQuadrant: 1,
+ SpeakerAuto: 0, AmpAuto: 2, NotesDroppedAuto: 0, MobilityAuto: false,
+ Speaker: 0, Amp: 4, SpeakerAmplified: 3, AmpAmplified: 1,
+ NotesDropped: 0, Penalties: 1, TrapNote: true, AvgCycle: 120,
+ Park: true, OnStage: false, Harmony: false, CollectedBy: "bob",
},
},
}
@@ -416,8 +408,10 @@
},
{
ActionTaken: &submit_2024_actions.ActionTypeT{
- Type: submit_2024_actions.ActionTypePenaltyAction,
- Value: &submit_2024_actions.PenaltyActionT{},
+ Type: submit_2024_actions.ActionTypePenaltyAction,
+ Value: &submit_2024_actions.PenaltyActionT{
+ Penalties: 5,
+ },
},
Timestamp: 2400,
},
@@ -485,7 +479,7 @@
MatchNumber: 3, SetNumber: 1, CompLevel: "quals", StartingQuadrant: 2,
SpeakerAuto: 0, AmpAuto: 1, NotesDroppedAuto: 1, MobilityAuto: true,
Speaker: 0, Amp: 0, SpeakerAmplified: 1, AmpAmplified: 1,
- NotesDropped: 0, Penalties: 1, TrapNote: false, AvgCycle: 950,
+ NotesDropped: 0, Penalties: 5, TrapNote: false, AvgCycle: 950,
Park: false, OnStage: false, Harmony: true, CollectedBy: "",
}
diff --git a/scouting/www/BUILD b/scouting/www/BUILD
index 55e9a8f..a403bf3 100644
--- a/scouting/www/BUILD
+++ b/scouting/www/BUILD
@@ -29,12 +29,12 @@
name = "static_files",
app_files = ":app",
pictures = [
- "//third_party/y2023/field:pictures",
+ "//third_party/y2024/field:pictures",
],
replace_prefixes = {
"prod": "",
"dev": "",
- "third_party/y2023": "pictures",
+ "third_party/y2024": "pictures",
},
tags = [
"no-remote-cache",
diff --git a/scouting/www/entry/BUILD b/scouting/www/entry/BUILD
index 2884f23..98b457b 100644
--- a/scouting/www/entry/BUILD
+++ b/scouting/www/entry/BUILD
@@ -12,7 +12,7 @@
":node_modules/@angular/forms",
"//scouting/webserver/requests/messages:error_response_ts_fbs",
"//scouting/webserver/requests/messages:request_all_matches_response_ts_fbs",
- "//scouting/webserver/requests/messages:submit_actions_ts_fbs",
+ "//scouting/webserver/requests/messages:submit_2024_actions_ts_fbs",
"//scouting/www/rpc",
"@com_github_google_flatbuffers//ts:flatbuffers_ts",
],
diff --git a/scouting/www/entry/entry.component.css b/scouting/www/entry/entry.component.css
index 38e9072..246887c 100644
--- a/scouting/www/entry/entry.component.css
+++ b/scouting/www/entry/entry.component.css
@@ -11,15 +11,10 @@
touch-action: manipulation;
}
-#switchFldbtn {
- width: 15%;
- display: block;
- margin: 0 auto;
- box-shadow: 2px 2px 1px #ccc;
- max-width: 105px;
- text-align: center;
+.row ul div span {
+ padding: 0px;
}
-.row ul div span {
+input label {
padding: 0px;
}
diff --git a/scouting/www/entry/entry.component.ts b/scouting/www/entry/entry.component.ts
index 5a93251..b3e1e92 100644
--- a/scouting/www/entry/entry.component.ts
+++ b/scouting/www/entry/entry.component.ts
@@ -11,19 +11,19 @@
import {Builder, ByteBuffer} from 'flatbuffers';
import {ErrorResponse} from '../../webserver/requests/messages/error_response_generated';
import {
- ObjectType,
- ScoreLevel,
- SubmitActions,
StartMatchAction,
+ ScoreType,
+ StageType,
+ Submit2024Actions,
MobilityAction,
- AutoBalanceAction,
- PickupObjectAction,
- PlaceObjectAction,
+ PenaltyAction,
+ PickupNoteAction,
+ PlaceNoteAction,
RobotDeathAction,
EndMatchAction,
ActionType,
Action,
-} from '../../webserver/requests/messages/submit_actions_generated';
+} from '../../webserver/requests/messages/submit_2024_actions_generated';
import {Match} from '../../webserver/requests/messages/request_all_matches_response_generated';
import {MatchListRequestor} from '@org_frc971/scouting/www/rpc';
@@ -62,23 +62,14 @@
mobility: boolean;
}
| {
- type: 'autoBalanceAction';
+ type: 'pickupNoteAction';
timestamp?: number;
- docked: boolean;
- engaged: boolean;
- balanceAttempt: boolean;
- }
- | {
- type: 'pickupObjectAction';
- timestamp?: number;
- objectType: ObjectType;
auto?: boolean;
}
| {
- type: 'placeObjectAction';
+ type: 'placeNoteAction';
timestamp?: number;
- objectType?: ObjectType;
- scoreLevel: ScoreLevel;
+ scoreType: ScoreType;
auto?: boolean;
}
| {
@@ -87,10 +78,14 @@
robotOn: boolean;
}
| {
+ type: 'penaltyAction';
+ timestamp?: number;
+ penalties: number;
+ }
+ | {
type: 'endMatchAction';
- docked: boolean;
- engaged: boolean;
- balanceAttempt: boolean;
+ stageType: StageType;
+ trapNote: boolean;
timestamp?: number;
}
| {
@@ -98,6 +93,12 @@
// It is used for undoing purposes.
type: 'endAutoPhase';
timestamp?: number;
+ }
+ | {
+ // This is not a action that is submitted,
+ // It is used for undoing purposes.
+ type: 'endTeleopPhase';
+ timestamp?: number;
};
@Component({
@@ -110,8 +111,7 @@
// of radio buttons.
readonly COMP_LEVELS = COMP_LEVELS;
readonly COMP_LEVEL_LABELS = COMP_LEVEL_LABELS;
- readonly ObjectType = ObjectType;
- readonly ScoreLevel = ScoreLevel;
+ readonly ScoreType = ScoreType;
section: Section = 'Team Selection';
@Input() matchNumber: number = 1;
@@ -127,10 +127,10 @@
errorMessage: string = '';
autoPhase: boolean = true;
mobilityCompleted: boolean = false;
- lastObject: ObjectType = null;
preScouting: boolean = false;
matchStartTimestamp: number = 0;
+ penalties: number = 0;
teamSelectionIsValid = false;
@@ -192,6 +192,20 @@
return false;
}
+ addPenalty(): void {
+ this.penalties += 1;
+ }
+
+ removePenalty(): void {
+ if (this.penalties > 0) {
+ this.penalties -= 1;
+ }
+ }
+
+ addPenalties(): void {
+ this.addAction({type: 'penaltyAction', penalties: this.penalties});
+ }
+
addAction(action: ActionT): void {
if (action.type == 'startMatchAction') {
// Unix nanosecond timestamp.
@@ -202,27 +216,17 @@
action.timestamp = Date.now() * 1e6 - this.matchStartTimestamp;
}
+ if (action.type == 'endMatchAction') {
+ // endMatchAction occurs at the same time as penaltyAction so add to its timestamp to make it unique.
+ action.timestamp += 1;
+ }
+
if (action.type == 'mobilityAction') {
this.mobilityCompleted = true;
}
- if (action.type == 'autoBalanceAction') {
- // Timestamp is a unique index in the database so
- // adding one makes sure it dosen't overlap with the
- // start teleop action that is added at the same time.
- action.timestamp += 1;
- }
-
- if (
- action.type == 'pickupObjectAction' ||
- action.type == 'placeObjectAction'
- ) {
+ if (action.type == 'pickupNoteAction' || action.type == 'placeNoteAction') {
action.auto = this.autoPhase;
- if (action.type == 'pickupObjectAction') {
- this.lastObject = action.objectType;
- } else if (action.type == 'placeObjectAction') {
- action.objectType = this.lastObject;
- }
}
this.actionList.push(action);
}
@@ -233,14 +237,23 @@
switch (lastAction?.type) {
case 'endAutoPhase':
this.autoPhase = true;
- case 'pickupObjectAction':
+ this.section = 'Pickup';
+ case 'pickupNoteAction':
this.section = 'Pickup';
break;
- case 'placeObjectAction':
+ case 'endTeleopPhase':
+ this.section = 'Pickup';
+ break;
+ case 'placeNoteAction':
this.section = 'Place';
break;
case 'endMatchAction':
- this.section = 'Pickup';
+ this.section = 'Endgame';
+ case 'mobilityAction':
+ this.mobilityCompleted = false;
+ break;
+ case 'startMatchAction':
+ this.section = 'Init';
break;
case 'robotDeathAction':
// TODO(FILIP): Return user to the screen they
@@ -254,12 +267,12 @@
}
}
- stringifyObjectType(objectType: ObjectType): String {
- return ObjectType[objectType];
+ stringifyScoreType(scoreType: ScoreType): String {
+ return ScoreType[scoreType];
}
- stringifyScoreLevel(scoreLevel: ScoreLevel): String {
- return ScoreLevel[scoreLevel];
+ stringifyStageType(stageType: StageType): String {
+ return StageType[stageType];
}
changeSectionTo(target: Section) {
@@ -276,7 +289,7 @@
this.header.nativeElement.scrollIntoView();
}
- async submitActions() {
+ async submit2024Actions() {
const builder = new Builder();
const actionOffsets: number[] = [];
@@ -307,49 +320,42 @@
mobilityActionOffset
);
break;
- case 'autoBalanceAction':
- const autoBalanceActionOffset =
- AutoBalanceAction.createAutoBalanceAction(
- builder,
- action.docked,
- action.engaged,
- action.balanceAttempt
- );
+ case 'penaltyAction':
+ const penaltyActionOffset = PenaltyAction.createPenaltyAction(
+ builder,
+ action.penalties
+ );
actionOffset = Action.createAction(
builder,
BigInt(action.timestamp || 0),
- ActionType.AutoBalanceAction,
- autoBalanceActionOffset
+ ActionType.PenaltyAction,
+ penaltyActionOffset
);
break;
-
- case 'pickupObjectAction':
- const pickupObjectActionOffset =
- PickupObjectAction.createPickupObjectAction(
+ case 'pickupNoteAction':
+ const pickupNoteActionOffset =
+ PickupNoteAction.createPickupNoteAction(
builder,
- action.objectType,
action.auto || false
);
actionOffset = Action.createAction(
builder,
BigInt(action.timestamp || 0),
- ActionType.PickupObjectAction,
- pickupObjectActionOffset
+ ActionType.PickupNoteAction,
+ pickupNoteActionOffset
);
break;
- case 'placeObjectAction':
- const placeObjectActionOffset =
- PlaceObjectAction.createPlaceObjectAction(
- builder,
- action.objectType,
- action.scoreLevel,
- action.auto || false
- );
+ case 'placeNoteAction':
+ const placeNoteActionOffset = PlaceNoteAction.createPlaceNoteAction(
+ builder,
+ action.scoreType,
+ action.auto || false
+ );
actionOffset = Action.createAction(
builder,
BigInt(action.timestamp || 0),
- ActionType.PlaceObjectAction,
- placeObjectActionOffset
+ ActionType.PlaceNoteAction,
+ placeNoteActionOffset
);
break;
@@ -367,9 +373,8 @@
case 'endMatchAction':
const endMatchActionOffset = EndMatchAction.createEndMatchAction(
builder,
- action.docked,
- action.engaged,
- action.balanceAttempt
+ action.stageType,
+ action.trapNote
);
actionOffset = Action.createAction(
builder,
@@ -383,6 +388,10 @@
// Not important action.
break;
+ case 'endTeleopPhase':
+ // Not important action.
+ break;
+
default:
throw new Error(`Unknown action type`);
}
@@ -394,21 +403,21 @@
const teamNumberFb = builder.createString(this.teamNumber);
const compLevelFb = builder.createString(this.compLevel);
- const actionsVector = SubmitActions.createActionsListVector(
+ const actionsVector = Submit2024Actions.createActionsListVector(
builder,
actionOffsets
);
- SubmitActions.startSubmitActions(builder);
- SubmitActions.addTeamNumber(builder, teamNumberFb);
- SubmitActions.addMatchNumber(builder, this.matchNumber);
- SubmitActions.addSetNumber(builder, this.setNumber);
- SubmitActions.addCompLevel(builder, compLevelFb);
- SubmitActions.addActionsList(builder, actionsVector);
- SubmitActions.addPreScouting(builder, this.preScouting);
- builder.finish(SubmitActions.endSubmitActions(builder));
+ Submit2024Actions.startSubmit2024Actions(builder);
+ Submit2024Actions.addTeamNumber(builder, teamNumberFb);
+ Submit2024Actions.addMatchNumber(builder, this.matchNumber);
+ Submit2024Actions.addSetNumber(builder, this.setNumber);
+ Submit2024Actions.addCompLevel(builder, compLevelFb);
+ Submit2024Actions.addActionsList(builder, actionsVector);
+ Submit2024Actions.addPreScouting(builder, this.preScouting);
+ builder.finish(Submit2024Actions.endSubmit2024Actions(builder));
const buffer = builder.asUint8Array();
- const res = await fetch('/requests/submit/submit_actions', {
+ const res = await fetch('/requests/submit/submit_2024_actions', {
method: 'POST',
body: buffer,
});
diff --git a/scouting/www/entry/entry.ng.html b/scouting/www/entry/entry.ng.html
index 43575cd..9490237 100644
--- a/scouting/www/entry/entry.ng.html
+++ b/scouting/www/entry/entry.ng.html
@@ -81,7 +81,7 @@
<h2>Select Starting Position</h2>
<img
id="field_starting_positions_image"
- src="/sha256/b71def525fb78486617a8b350c0ba6907e8ea25f78d4084a932cba8ae922528c/pictures/field/field.jpg"
+ src="/sha256/bb83d2c976c1496bb470371821d1d1882d6baf31178009a6f6cba579880c6a03/pictures/field/2024_field.png"
alt="Starting Positions Image"
class="img-fluid"
/>
@@ -129,15 +129,9 @@
</button>
<button
class="btn btn-warning"
- (click)="changeSectionTo('Place'); addAction({type: 'pickupObjectAction', objectType: ObjectType.kCone});"
+ (click)="changeSectionTo('Place'); addAction({type: 'pickupNoteAction'});"
>
- CONE
- </button>
- <button
- class="btn btn-primary"
- (click)="changeSectionTo('Place'); addAction({type: 'pickupObjectAction', objectType: ObjectType.kCube});"
- >
- CUBE
+ NOTE
</button>
<button
*ngIf="autoPhase && !mobilityCompleted"
@@ -146,49 +140,35 @@
>
Mobility
</button>
- <!-- 'Balancing' during auto. -->
- <div *ngIf="autoPhase" class="d-grid gap-2">
- <label>
- <input
- #docked
- type="radio"
- id="option1"
- name="docked_engaged"
- value="docked"
- />
- Docked (on the charging station)
- </label>
- <label>
- <input
- #engaged
- type="radio"
- id="option2"
- name="docked_engaged"
- value="dockedengaged"
- />
- Docked & Engaged (level & station lights on)
- </label>
- <label>
- <input
- #attempted
- type="radio"
- id="option3"
- name="docked_engaged"
- value="failed"
- />
- Attempted to dock and engage but failed
- </label>
+ <div style="display: flex">
+ <h5>Penalties :</h5>
<button
- class="btn btn-dark"
- (click)="autoPhase = false; addAction({type: 'endAutoPhase'}); addAction({type: 'autoBalanceAction', docked: docked.checked, engaged: engaged.checked, balanceAttempt: attempted.checked});"
+ class="btn-light"
+ style="width: 40px; margin-right: 15px"
+ (click)="removePenalty()"
>
- Start Teleop
+ -
+ </button>
+ <p>{{this.penalties}}</p>
+ <button
+ class="btn-light"
+ style="width: 40px; margin-left: 15px"
+ (click)="addPenalty()"
+ >
+ +
</button>
</div>
<button
+ *ngIf="autoPhase"
+ class="btn btn-dark"
+ (click)="autoPhase = false; addAction({type: 'endAutoPhase'});"
+ >
+ Start Teleop
+ </button>
+ <button
*ngIf="!autoPhase"
class="btn btn-info"
- (click)="changeSectionTo('Endgame')"
+ (click)="changeSectionTo('Endgame'); addAction({type: 'endTeleopPhase'});"
>
Endgame
</button>
@@ -212,23 +192,62 @@
>
DEAD
</button>
+ <div *ngIf="!autoPhase" class="d-grid gap-1" style="padding: 0">
+ <div
+ style="
+ display: flex-wrap;
+ padding: 0;
+ justify-content: center;
+ text-align: center;
+ align-content: center;
+ margin: 0;
+ "
+ >
+ <button
+ class="btn btn-success"
+ (click)="changeSectionTo('Pickup'); addAction({type: 'placeNoteAction', scoreType: ScoreType.kAMP});"
+ style="width: 48%; height: 12vh; margin: 0px 10px 10px 0px"
+ >
+ AMP
+ </button>
+
+ <button
+ class="btn btn-warning"
+ (click)="changeSectionTo('Pickup'); addAction({type: 'placeNoteAction', scoreType: ScoreType.kAMP_AMPLIFIED});"
+ style="width: 48%; height: 12vh; margin: 0px 0px 10px 0px"
+ >
+ AMP AMPLIFIED
+ </button>
+ <button
+ class="btn btn-success"
+ (click)="changeSectionTo('Pickup'); addAction({type: 'placeNoteAction', scoreType: ScoreType.kSPEAKER});"
+ style="width: 48%; height: 12vh; margin: 0px 10px 0px 0px"
+ >
+ SPEAKER
+ </button>
+ <button
+ class="btn btn-warning"
+ (click)="changeSectionTo('Pickup'); addAction({type: 'placeNoteAction', scoreType: ScoreType.kSPEAKER_AMPLIFIED});"
+ style="width: 48%; height: 12vh; margin: 0px 0px 0px 0px"
+ >
+ SPEAKER AMPLIFIED
+ </button>
+ </div>
+ </div>
+
<button
+ *ngIf="autoPhase"
class="btn btn-success"
- (click)="changeSectionTo('Pickup'); addAction({type: 'placeObjectAction', scoreLevel: ScoreLevel.kHigh});"
+ (click)="changeSectionTo('Pickup'); addAction({type: 'placeNoteAction', scoreType: ScoreType.kAMP});"
>
- HIGH
+ AMP
</button>
<button
+ *ngIf="autoPhase"
class="btn btn-warning"
- (click)="changeSectionTo('Pickup'); addAction({type: 'placeObjectAction', scoreLevel: ScoreLevel.kMiddle});"
+ (click)="changeSectionTo('Pickup'); addAction({type: 'placeNoteAction', scoreType: ScoreType.kSPEAKER});"
>
- MID
- </button>
- <button
- class="btn btn-danger"
- (click)="changeSectionTo('Pickup'); addAction({type: 'placeObjectAction', scoreLevel: ScoreLevel.kLow});"
- >
- LOW
+ SPEAKER
</button>
<button
*ngIf="autoPhase && !mobilityCompleted"
@@ -237,58 +256,35 @@
>
Mobility
</button>
- <!-- Impossible to place supercharged pieces in auto. -->
- <div *ngIf="autoPhase == false" class="d-grid gap-2">
+ <div style="display: flex">
+ <h5>Penalties :</h5>
<button
- class="btn btn-dark"
- (click)="changeSectionTo('Pickup'); addAction({type: 'placeObjectAction', scoreLevel: ScoreLevel.kSupercharged});"
+ class="btn-light"
+ style="width: 40px; margin-right: 15px"
+ (click)="removePenalty()"
>
- SUPERCHARGED
+ -
</button>
- </div>
- <!-- 'Balancing' during auto. -->
- <div *ngIf="autoPhase" class="d-grid gap-1">
- <label>
- <input
- #docked
- type="radio"
- id="option1"
- name="docked_engaged"
- value="docked"
- />
- Docked (on the charging station)
- </label>
- <label>
- <input
- #engaged
- type="radio"
- id="option2"
- name="docked_engaged"
- value="dockedengaged"
- />
- Docked & Engaged (level & station lights on)
- </label>
- <label>
- <input
- #attempted
- type="radio"
- id="option3"
- name="docked_engaged"
- value="failed"
- />
- Attempted to dock and engage but failed
- </label>
+ <p>{{this.penalties}}</p>
<button
- class="btn btn-dark"
- (click)="autoPhase = false; addAction({type: 'endAutoPhase'}); addAction({type: 'autoBalanceAction', docked: docked.checked, engaged: engaged.checked, balanceAttempt: attempted.checked});"
+ class="btn-light"
+ style="width: 40px; margin-left: 15px"
+ (click)="addPenalty()"
>
- Start Teleop
+ +
</button>
</div>
<button
+ class="btn btn-dark"
+ *ngIf="autoPhase"
+ (click)="autoPhase = false; addAction({type: 'endAutoPhase'});"
+ >
+ Start Teleop
+ </button>
+ <button
*ngIf="!autoPhase"
class="btn btn-info"
- (click)="changeSectionTo('Endgame')"
+ (click)="changeSectionTo('Endgame'); addAction({type: 'endTeleopPhase'});"
>
Endgame
</button>
@@ -298,7 +294,7 @@
<h6 class="text-muted">
Last Action: {{actionList[actionList.length - 1].type}}
</h6>
- <div class="d-grid gap-5">
+ <div class="d-grid gap-4">
<button class="btn btn-secondary" (click)="undoLastAction()">UNDO</button>
<button
class="btn btn-danger"
@@ -306,40 +302,68 @@
>
DEAD
</button>
- <label>
+ <label style="padding: 0">
<input
- #docked
+ #park
type="radio"
id="option1"
- name="docked_engaged"
- value="docked"
+ name="endgameaction"
+ value="park"
/>
- Docked (on the charging station)
+ Park
</label>
- <label>
+ <label style="padding: 0">
<input
- #engaged
+ #onStage
type="radio"
id="option2"
- name="docked_engaged"
- value="dockedengaged"
+ name="endgameaction"
+ value="onStage"
/>
- Docked & Engaged (level & station lights on)
+ On Stage
</label>
- <label>
+ <label style="padding: 0">
<input
- #attempted
+ #harmony
type="radio"
id="option3"
- name="docked_engaged"
- value="failed"
+ name="endgameaction"
+ value="harmony"
/>
- Attempted to dock and engage but failed
+ Harmony
</label>
+ <label style="padding: 0">
+ <input
+ #trapNote
+ type="checkbox"
+ id="trapnote"
+ name="trapnote"
+ value="trapNote"
+ />
+ Trap Note
+ </label>
+ <div style="display: flex">
+ <h5>Penalties :</h5>
+ <button
+ class="btn-light"
+ style="width: 40px; margin-right: 15px"
+ (click)="removePenalty()"
+ >
+ -
+ </button>
+ <p>{{this.penalties}}</p>
+ <button
+ class="btn-light"
+ style="width: 40px; margin-left: 15px"
+ (click)="addPenalty()"
+ >
+ +
+ </button>
+ </div>
<button
*ngIf="!autoPhase"
class="btn btn-info"
- (click)="changeSectionTo('Review and Submit'); addAction({type: 'endMatchAction', docked: docked.checked, engaged: engaged.checked, balanceAttempt: attempted.checked});"
+ (click)="changeSectionTo('Review and Submit'); addPenalties(); addAction({type: 'endMatchAction', park: park.checked, onStage: onStage.checked, harmony: harmony.checked, trapNote: trapNote.checked});"
>
End Match
</button>
@@ -354,12 +378,6 @@
>
Revive
</button>
- <button
- class="btn btn-info"
- (click)="changeSectionTo('Review and Submit'); addAction({type: 'endMatchAction', docked: docked.checked, engaged: engaged.checked});"
- >
- End Match
- </button>
</div>
</div>
<div *ngSwitchCase="'Review and Submit'" id="Review" class="container-fluid">
@@ -374,21 +392,14 @@
<span *ngSwitchCase="'startMatchAction'">
Started match at position {{action.position}}
</span>
- <span *ngSwitchCase="'pickupObjectAction'">
- Picked up {{stringifyObjectType(action.objectType)}}
- </span>
- <span *ngSwitchCase="'placeObjectAction'">
- Placed at {{stringifyScoreLevel(action.scoreLevel)}}
- </span>
- <span *ngSwitchCase="'autoBalanceAction'">
- Docked: {{action.docked}}, engaged: {{action.engaged}}, attempted
- to balance and engage: {{action.balanceAttempt}}
+ <span *ngSwitchCase="'pickupNoteAction'">Picked up Note</span>
+ <span *ngSwitchCase="'placeNoteAction'">
+ Placed at {{stringifyScoreType(action.scoreType)}}
</span>
<span *ngSwitchCase="'endAutoPhase'">Ended auto phase</span>
<span *ngSwitchCase="'endMatchAction'">
- Ended Match; docked: {{action.docked}}, engaged:
- {{action.engaged}}, attempted to dock and engage:
- {{action.balanceAttempt}}
+ Ended Match; park: {{action.park}}, onStage: {{action.onStage}},
+ harmony: {{action.harmony}}, trapNote: {{action.trapNote}}
</span>
<span *ngSwitchCase="'robotDeathAction'">
Robot on: {{action.robotOn}}
@@ -397,13 +408,18 @@
Mobility: {{action.mobility}}
</span>
<span *ngSwitchDefault>{{action.type}}</span>
+ <span *ngSwitchCase="'penaltyAction'">
+ Penalties: {{action.penalties}}
+ </span>
</div>
</li>
</ul>
</div>
<div class="d-grid gap-5">
<button class="btn btn-secondary" (click)="undoLastAction()">UNDO</button>
- <button class="btn btn-warning" (click)="submitActions();">Submit</button>
+ <button class="btn btn-warning" (click)="submit2024Actions();">
+ Submit
+ </button>
</div>
</div>
<div *ngSwitchCase="'Success'" id="Success" class="container-fluid">
diff --git a/scouting/www/pit_scouting/pit_scouting.component.ts b/scouting/www/pit_scouting/pit_scouting.component.ts
index 58e7647..7bb884c 100644
--- a/scouting/www/pit_scouting/pit_scouting.component.ts
+++ b/scouting/www/pit_scouting/pit_scouting.component.ts
@@ -57,6 +57,8 @@
const builder = new Builder();
const teamNumber = builder.createString(this.teamNumber);
const pitImage = builder.createString(
+ // Remove anything between /s in order to end up with only the file name.
+ // Example : path/to/file.txt -> file.txt
this.pitImage.toString().replace(/^.*[\\\/]/, '')
);
const imageData = SubmitPitImage.createImageDataVector(
diff --git a/scouting/www/rpc/BUILD b/scouting/www/rpc/BUILD
index ab28581..d1367ea 100644
--- a/scouting/www/rpc/BUILD
+++ b/scouting/www/rpc/BUILD
@@ -11,8 +11,8 @@
generate_public_api = False,
deps = [
"//scouting/webserver/requests/messages:error_response_ts_fbs",
- "//scouting/webserver/requests/messages:request_2023_data_scouting_response_ts_fbs",
- "//scouting/webserver/requests/messages:request_2023_data_scouting_ts_fbs",
+ "//scouting/webserver/requests/messages:request_2024_data_scouting_response_ts_fbs",
+ "//scouting/webserver/requests/messages:request_2024_data_scouting_ts_fbs",
"//scouting/webserver/requests/messages:request_all_driver_rankings_response_ts_fbs",
"//scouting/webserver/requests/messages:request_all_driver_rankings_ts_fbs",
"//scouting/webserver/requests/messages:request_all_matches_response_ts_fbs",
diff --git a/scouting/www/rpc/view_data_requestor.ts b/scouting/www/rpc/view_data_requestor.ts
index f1f2b79..74fc212 100644
--- a/scouting/www/rpc/view_data_requestor.ts
+++ b/scouting/www/rpc/view_data_requestor.ts
@@ -11,16 +11,16 @@
Ranking,
RequestAllDriverRankingsResponse,
} from '../../webserver/requests/messages/request_all_driver_rankings_response_generated';
-import {Request2023DataScouting} from '../../webserver/requests/messages/request_2023_data_scouting_generated';
+import {Request2024DataScouting} from '../../webserver/requests/messages/request_2024_data_scouting_generated';
import {
PitImage,
RequestAllPitImagesResponse,
} from '../../webserver/requests/messages/request_all_pit_images_response_generated';
import {RequestAllPitImages} from '../../webserver/requests/messages/request_all_pit_images_generated';
import {
- Stats2023,
- Request2023DataScoutingResponse,
-} from '../../webserver/requests/messages/request_2023_data_scouting_response_generated';
+ Stats2024,
+ Request2024DataScoutingResponse,
+} from '../../webserver/requests/messages/request_2024_data_scouting_response_generated';
@Injectable({providedIn: 'root'})
export class ViewDataRequestor {
@@ -82,15 +82,15 @@
return driverRankingList;
}
// Returns all data scouting entries from the database.
- async fetchStats2023List(): Promise<Stats2023[]> {
+ async fetchStats2024List(): Promise<Stats2024[]> {
let fbBuffer = await this.fetchFromServer(
- Request2023DataScouting.startRequest2023DataScouting,
- Request2023DataScouting.endRequest2023DataScouting,
- '/requests/request/2023_data_scouting'
+ Request2024DataScouting.startRequest2024DataScouting,
+ Request2024DataScouting.endRequest2024DataScouting,
+ '/requests/request/2024_data_scouting'
);
const parsedResponse =
- Request2023DataScoutingResponse.getRootAsRequest2023DataScoutingResponse(
+ Request2024DataScoutingResponse.getRootAsRequest2024DataScoutingResponse(
fbBuffer
);
diff --git a/scouting/www/view/BUILD b/scouting/www/view/BUILD
index 67c7e3b..738ea00 100644
--- a/scouting/www/view/BUILD
+++ b/scouting/www/view/BUILD
@@ -10,11 +10,11 @@
],
deps = [
":node_modules/@angular/forms",
- "//scouting/webserver/requests/messages:delete_2023_data_scouting_response_ts_fbs",
- "//scouting/webserver/requests/messages:delete_2023_data_scouting_ts_fbs",
+ "//scouting/webserver/requests/messages:delete_2024_data_scouting_response_ts_fbs",
+ "//scouting/webserver/requests/messages:delete_2024_data_scouting_ts_fbs",
"//scouting/webserver/requests/messages:error_response_ts_fbs",
- "//scouting/webserver/requests/messages:request_2023_data_scouting_response_ts_fbs",
- "//scouting/webserver/requests/messages:request_2023_data_scouting_ts_fbs",
+ "//scouting/webserver/requests/messages:request_2024_data_scouting_response_ts_fbs",
+ "//scouting/webserver/requests/messages:request_2024_data_scouting_ts_fbs",
"//scouting/webserver/requests/messages:request_all_driver_rankings_response_ts_fbs",
"//scouting/webserver/requests/messages:request_all_driver_rankings_ts_fbs",
"//scouting/webserver/requests/messages:request_all_notes_response_ts_fbs",
diff --git a/scouting/www/view/view.component.ts b/scouting/www/view/view.component.ts
index 64b0680..ea9a61f 100644
--- a/scouting/www/view/view.component.ts
+++ b/scouting/www/view/view.component.ts
@@ -6,9 +6,9 @@
RequestAllDriverRankingsResponse,
} from '../../webserver/requests/messages/request_all_driver_rankings_response_generated';
import {
- Stats2023,
- Request2023DataScoutingResponse,
-} from '../../webserver/requests/messages/request_2023_data_scouting_response_generated';
+ Stats2024,
+ Request2024DataScoutingResponse,
+} from '../../webserver/requests/messages/request_2024_data_scouting_response_generated';
import {
PitImage,
@@ -19,12 +19,12 @@
Note,
RequestAllNotesResponse,
} from '../../webserver/requests/messages/request_all_notes_response_generated';
-import {Delete2023DataScouting} from '../../webserver/requests/messages/delete_2023_data_scouting_generated';
-import {Delete2023DataScoutingResponse} from '../../webserver/requests/messages/delete_2023_data_scouting_response_generated';
+import {Delete2024DataScouting} from '../../webserver/requests/messages/delete_2024_data_scouting_generated';
+import {Delete2024DataScoutingResponse} from '../../webserver/requests/messages/delete_2024_data_scouting_response_generated';
import {ViewDataRequestor} from '../rpc';
-type Source = 'Notes' | 'Stats2023' | 'PitImages' | 'DriverRanking';
+type Source = 'Notes' | 'Stats2024' | 'PitImages' | 'DriverRanking';
//TODO(Filip): Deduplicate
const COMP_LEVEL_LABELS = {
@@ -63,7 +63,7 @@
noteList: Note[] = [];
driverRankingList: Ranking[] = [];
pitImageList: PitImage[][] = [];
- statList: Stats2023[] = [];
+ statList: Stats2024[] = [];
// Fetch notes on initialization.
ngOnInit() {
@@ -123,8 +123,8 @@
this.fetchNotes();
}
- case 'Stats2023': {
- this.fetchStats2023();
+ case 'Stats2024': {
+ this.fetchStats2024();
}
case 'PitImages': {
@@ -162,7 +162,7 @@
}
// Gets called when a user clicks the delete icon.
- async deleteDataScouting(
+ async delete2024DataScouting(
compLevel: string,
matchNumber: number,
setNumber: number,
@@ -172,17 +172,17 @@
'block_alerts'
) as HTMLInputElement;
if (block_alerts.checked || window.confirm('Actually delete data?')) {
- await this.requestDeleteDataScouting(
+ await this.requestDelete2024DataScouting(
compLevel,
matchNumber,
setNumber,
teamNumber
);
- await this.fetchStats2023();
+ await this.fetchStats2024();
}
}
- async requestDeleteDataScouting(
+ async requestDelete2024DataScouting(
compLevel: string,
matchNumber: number,
setNumber: number,
@@ -194,7 +194,7 @@
const teamNumberData = builder.createString(teamNumber);
builder.finish(
- Delete2023DataScouting.createDelete2023DataScouting(
+ Delete2024DataScouting.createDelete2024DataScouting(
builder,
compLevelData,
matchNumber,
@@ -204,7 +204,7 @@
);
const buffer = builder.asUint8Array();
- const res = await fetch('/requests/delete/delete_2023_data_scouting', {
+ const res = await fetch('/requests/delete/delete_2024_data_scouting', {
method: 'POST',
body: buffer,
});
@@ -270,12 +270,12 @@
}
// Fetch all data scouting (stats) data and store in statList.
- async fetchStats2023() {
+ async fetchStats2024() {
this.progressMessage = 'Fetching stats list. Please be patient.';
this.errorMessage = '';
try {
- this.statList = await this.viewDataRequestor.fetchStats2023List();
+ this.statList = await this.viewDataRequestor.fetchStats2024List();
this.progressMessage = 'Successfully fetched stats list.';
} catch (e) {
this.errorMessage = e;
diff --git a/scouting/www/view/view.ng.html b/scouting/www/view/view.ng.html
index 239548c..14e8c8a 100644
--- a/scouting/www/view/view.ng.html
+++ b/scouting/www/view/view.ng.html
@@ -24,10 +24,10 @@
<a
class="dropdown-item"
href="#"
- (click)="switchDataSource('Stats2023')"
+ (click)="switchDataSource('Stats2024')"
id="stats_source_dropdown"
>
- Stats
+ Stats2024
</a>
</li>
<li>
@@ -93,8 +93,8 @@
</tbody>
</table>
</div>
- <!-- Stats Data Display. -->
- <div *ngSwitchCase="'Stats2023'">
+ <!-- Stats2024 Data Display. -->
+ <div *ngSwitchCase="'Stats2024'">
<table class="table">
<thead>
<tr>
@@ -114,17 +114,17 @@
</tr>
</thead>
<tbody>
- <tr *ngFor="let stat2023 of statList; index as i;">
- <th scope="row">{{stat2023.matchNumber()}}</th>
- <td>{{stat2023.teamNumber()}}</td>
- <td>{{COMP_LEVEL_LABELS[stat2023.compLevel()]}}</td>
- <td>{{stat2023.collectedBy()}}</td>
+ <tr *ngFor="let stat2024 of statList; index as i;">
+ <th scope="row">{{stat2024.matchNumber()}}</th>
+ <td>{{stat2024.teamNumber()}}</td>
+ <td>{{COMP_LEVEL_LABELS[stat2024.compLevel()]}}</td>
+ <td>{{stat2024.collectedBy()}}</td>
<!-- Delete Icon. -->
<td>
<button
class="btn btn-danger"
id="delete_button_{{i}}"
- (click)="deleteDataScouting(stat2023.compLevel(), stat2023.matchNumber(), stat2023.setNumber(), stat2023.teamNumber())"
+ (click)="delete2024DataScouting(stat2024.compLevel(), stat2024.matchNumber(), stat2024.setNumber(), stat2024.teamNumber())"
>
<i class="bi bi-trash"></i>
</button>
diff --git a/third_party/flatbuffers/build_defs.bzl b/third_party/flatbuffers/build_defs.bzl
index 5f6d71b..da26cec 100644
--- a/third_party/flatbuffers/build_defs.bzl
+++ b/third_party/flatbuffers/build_defs.bzl
@@ -96,7 +96,7 @@
mnemonic = "Flatc",
progress_message = "Generating flatbuffer files for %{input}:",
)
- return [DefaultInfo(files = depset(outs), runfiles = ctx.runfiles(files = outs)), FlatbufferLibraryInfo(srcs = ctx.files.srcs)]
+ return [DefaultInfo(files = depset(outs)), FlatbufferLibraryInfo(srcs = ctx.files.srcs)]
_flatbuffer_library_compile = rule(
implementation = _flatbuffer_library_compile_impl,
diff --git a/third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h b/third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h
index efa4d89..6f9d7c8 100644
--- a/third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h
+++ b/third_party/flatbuffers/include/flatbuffers/flatbuffer_builder.h
@@ -787,7 +787,7 @@
/// where the vector is stored.
template<typename T>
Offset<Vector<const T *>> CreateVectorOfStructs(const T *v, size_t len) {
- StartVector(len * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
+ StartVector(len, sizeof(T), AlignOf<T>());
if (len > 0) {
PushBytes(reinterpret_cast<const uint8_t *>(v), sizeof(T) * len);
}
@@ -1211,7 +1211,7 @@
// Allocates space for a vector of structures.
// Must be completed with EndVectorOfStructs().
template<typename T> T *StartVectorOfStructs(size_t vector_size) {
- StartVector(vector_size * sizeof(T) / AlignOf<T>(), sizeof(T), AlignOf<T>());
+ StartVector(vector_size, sizeof(T), AlignOf<T>());
return reinterpret_cast<T *>(buf_.make_space(vector_size * sizeof(T)));
}
diff --git a/third_party/flatbuffers/include/flatbuffers/reflection.h b/third_party/flatbuffers/include/flatbuffers/reflection.h
index 1aa0863..84213c7 100644
--- a/third_party/flatbuffers/include/flatbuffers/reflection.h
+++ b/third_party/flatbuffers/include/flatbuffers/reflection.h
@@ -508,14 +508,19 @@
// root should point to the root type for this flatbuffer.
// buf should point to the start of flatbuffer data.
// length specifies the size of the flatbuffer data.
+// Returns true if the flatbuffer is valid. Returns false if either:
+// * The flatbuffer is incorrectly constructed (e.g., it points to memory
+// locations outside of the current memory buffer).
+// * The flatbuffer is too complex, and the flatbuffer verifier chosen to bail
+// when attempting to traverse the tree of tables.
bool Verify(const reflection::Schema &schema, const reflection::Object &root,
const uint8_t *buf, size_t length, uoffset_t max_depth = 64,
- uoffset_t max_tables = 1000000);
+ uoffset_t max_tables = 3000000);
bool VerifySizePrefixed(const reflection::Schema &schema,
const reflection::Object &root, const uint8_t *buf,
size_t length, uoffset_t max_depth = 64,
- uoffset_t max_tables = 1000000);
+ uoffset_t max_tables = 3000000);
} // namespace flatbuffers
diff --git a/third_party/flatbuffers/include/flatbuffers/reflection_generated.h b/third_party/flatbuffers/include/flatbuffers/reflection_generated.h
index 6a99e66..b340086 100644
--- a/third_party/flatbuffers/include/flatbuffers/reflection_generated.h
+++ b/third_party/flatbuffers/include/flatbuffers/reflection_generated.h
@@ -523,6 +523,7 @@
int64_t value = 0;
flatbuffers::unique_ptr<reflection::TypeT> union_type{};
std::vector<std::string> documentation{};
+ std::vector<flatbuffers::unique_ptr<reflection::KeyValueT>> attributes{};
EnumValT() = default;
EnumValT(const EnumValT &o);
EnumValT(EnumValT&&) FLATBUFFERS_NOEXCEPT = default;
@@ -603,6 +604,9 @@
const flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>> *attributes() const {
return GetPointer<const flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>> *>(VT_ATTRIBUTES);
}
+ flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>> *mutable_attributes() {
+ return GetPointer<flatbuffers::Vector<flatbuffers::Offset<reflection::KeyValue>> *>(VT_ATTRIBUTES);
+ }
void clear_attributes() {
ClearField(VT_ATTRIBUTES);
}
@@ -2462,7 +2466,8 @@
(lhs.name == rhs.name) &&
(lhs.value == rhs.value) &&
((lhs.union_type == rhs.union_type) || (lhs.union_type && rhs.union_type && *lhs.union_type == *rhs.union_type)) &&
- (lhs.documentation == rhs.documentation);
+ (lhs.documentation == rhs.documentation) &&
+ (lhs.attributes.size() == rhs.attributes.size() && std::equal(lhs.attributes.cbegin(), lhs.attributes.cend(), rhs.attributes.cbegin(), [](flatbuffers::unique_ptr<reflection::KeyValueT> const &a, flatbuffers::unique_ptr<reflection::KeyValueT> const &b) { return (a == b) || (a && b && *a == *b); }));
}
inline bool operator!=(const EnumValT &lhs, const EnumValT &rhs) {
@@ -2475,6 +2480,8 @@
value(o.value),
union_type((o.union_type) ? new reflection::TypeT(*o.union_type) : nullptr),
documentation(o.documentation) {
+ attributes.reserve(o.attributes.size());
+ for (const auto &attributes_ : o.attributes) { attributes.emplace_back((attributes_) ? new reflection::KeyValueT(*attributes_) : nullptr); }
}
inline EnumValT &EnumValT::operator=(EnumValT o) FLATBUFFERS_NOEXCEPT {
@@ -2482,6 +2489,7 @@
std::swap(value, o.value);
std::swap(union_type, o.union_type);
std::swap(documentation, o.documentation);
+ std::swap(attributes, o.attributes);
return *this;
}
@@ -2498,6 +2506,7 @@
{ auto _e = value(); _o->value = _e; }
{ auto _e = union_type(); if (_e) { if(_o->union_type) { _e->UnPackTo(_o->union_type.get(), _resolver); } else { _o->union_type = flatbuffers::unique_ptr<reflection::TypeT>(_e->UnPack(_resolver)); } } else if (_o->union_type) { _o->union_type.reset(); } }
{ auto _e = documentation(); if (_e) { _o->documentation.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { _o->documentation[_i] = _e->Get(_i)->str(); } } else { _o->documentation.resize(0); } }
+ { auto _e = attributes(); if (_e) { _o->attributes.resize(_e->size()); for (flatbuffers::uoffset_t _i = 0; _i < _e->size(); _i++) { if(_o->attributes[_i]) { _e->Get(_i)->UnPackTo(_o->attributes[_i].get(), _resolver); } else { _o->attributes[_i] = flatbuffers::unique_ptr<reflection::KeyValueT>(_e->Get(_i)->UnPack(_resolver)); }; } } else { _o->attributes.resize(0); } }
}
inline flatbuffers::Offset<EnumVal> EnumVal::Pack(flatbuffers::FlatBufferBuilder &_fbb, const EnumValT* _o, const flatbuffers::rehasher_function_t *_rehasher) {
@@ -2512,12 +2521,14 @@
auto _value = _o->value;
auto _union_type = _o->union_type ? CreateType(_fbb, _o->union_type.get(), _rehasher) : 0;
auto _documentation = _fbb.CreateVectorOfStrings(_o->documentation);
+ auto _attributes = _fbb.CreateVector<flatbuffers::Offset<reflection::KeyValue>> (_o->attributes.size(), [](size_t i, _VectorArgs *__va) { return CreateKeyValue(*__va->__fbb, __va->__o->attributes[i].get(), __va->__rehasher); }, &_va );
return reflection::CreateEnumVal(
_fbb,
_name,
_value,
_union_type,
- _documentation);
+ _documentation,
+ _attributes);
}
@@ -3211,21 +3222,24 @@
{ flatbuffers::ET_LONG, 0, -1 },
{ flatbuffers::ET_SEQUENCE, 0, 0 },
{ flatbuffers::ET_SEQUENCE, 0, 1 },
- { flatbuffers::ET_STRING, 1, -1 }
+ { flatbuffers::ET_STRING, 1, -1 },
+ { flatbuffers::ET_SEQUENCE, 1, 2 }
};
static const flatbuffers::TypeFunction type_refs[] = {
reflection::ObjectTypeTable,
- reflection::TypeTypeTable
+ reflection::TypeTypeTable,
+ reflection::KeyValueTypeTable
};
static const char * const names[] = {
"name",
"value",
"object",
"union_type",
- "documentation"
+ "documentation",
+ "attributes"
};
static const flatbuffers::TypeTable tt = {
- flatbuffers::ST_TABLE, 5, type_codes, type_refs, nullptr, nullptr, names
+ flatbuffers::ST_TABLE, 6, type_codes, type_refs, nullptr, nullptr, names
};
return &tt;
}
diff --git a/third_party/y2024/field/2024_field.png b/third_party/y2024/field/2024_field.png
new file mode 100644
index 0000000..c79e929
--- /dev/null
+++ b/third_party/y2024/field/2024_field.png
Binary files differ
diff --git a/third_party/y2024/field/BUILD b/third_party/y2024/field/BUILD
index 04346f5..04db591 100644
--- a/third_party/y2024/field/BUILD
+++ b/third_party/y2024/field/BUILD
@@ -2,9 +2,10 @@
name = "pictures",
srcs = [
# Picture from the FIRST inspires field drawings.
+ "2024.png",
# https://www.firstinspires.org/robotics/frc/playing-field
# Copyright 2024 FIRST
- "2024.png",
+ "2024_field.png",
],
visibility = ["//visibility:public"],
)
\ No newline at end of file