4 #include <unordered_map> 7 int main(
int argc,
char* argv[])
11 printf(
"Wrong number of arguments\nUsage: %s [filename]\n", argv[0]);
15 FILE*
file = fopen(argv[1],
"rb");
19 printf(
"Failed to open file: [%s]\n", argv[1]);
23 fseek(file, 0L, SEEK_END);
24 const size_t length =
static_cast<size_t>(ftell(file));
25 fseek(file, 0L, SEEK_SET);
26 std::vector<char>
buffer(length);
27 fread(buffer.data(),
sizeof(char), length, file);
30 const auto bt_header_size = flatbuffers::ReadScalar<uint32_t>(&buffer[0]);
34 std::unordered_map<uint16_t, std::string> names_by_uid;
35 std::unordered_map<uint16_t, const Serialization::TreeNode*> node_by_uid;
37 for (
const Serialization::TreeNode* node : *(behavior_tree->nodes()))
39 names_by_uid.insert({node->uid(), std::string(node->instance_name()->c_str())});
40 node_by_uid.insert({node->uid(), node});
43 printf(
"----------------------------\n");
45 std::function<void(uint16_t, int)> recursiveStep;
47 recursiveStep = [&](uint16_t uid,
int indent) {
48 for (
int i = 0; i < indent; i++)
51 names_by_uid[uid] = std::string(
" ") + names_by_uid[uid];
53 printf(
"%s\n", names_by_uid[uid].c_str());
54 std::cout << std::flush;
56 const auto& node = node_by_uid[uid];
58 for (
size_t i = 0; i < node->children_uid()->size(); i++)
60 recursiveStep(node->children_uid()->Get(i), indent + 1);
64 recursiveStep(behavior_tree->root_uid(), 0);
66 printf(
"----------------------------\n");
68 constexpr
const char* whitespaces =
" ";
69 constexpr
const size_t ws_count = 25;
94 for (
size_t index = bt_header_size + 4; index < length; index += 12)
96 const uint16_t uid = flatbuffers::ReadScalar<uint16_t>(&buffer[index + 8]);
97 const std::string& name = names_by_uid[uid];
98 const uint32_t t_sec = flatbuffers::ReadScalar<uint32_t>(&buffer[index]);
99 const uint32_t t_usec = flatbuffers::ReadScalar<uint32_t>(&buffer[index + 4]);
101 printf(
"[%d.%06d]: %s%s %s -> %s\n", t_sec, t_usec, name.c_str(),
102 &whitespaces[std::min(ws_count, name.size())],
103 printStatus(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[index + 10])),
104 printStatus(flatbuffers::ReadScalar<Serialization::NodeStatus>(&buffer[index + 11])));
static raw_event_t * buffer
int main(int argc, char *argv[])
const Serialization::BehaviorTree * GetBehaviorTree(const void *buf)