blob: 73ddd4e36dc846322a29c8c22bad41147f973fcc [file] [log] [blame]
Ravago Jones09067de2023-03-29 18:44:43 -07001#include "aos/configuration.h"
2#include "aos/events/event_loop_generated.h"
3#include "aos/events/logging/log_reader.h"
4#include "aos/init.h"
5#include "frc971/can_logger/asc_logger.h"
6#include "frc971/can_logger/can_logging_generated.h"
7
8DEFINE_string(node, "", "Node to replay from the perspective of.");
9DEFINE_string(output_path, "/tmp/can_log.asc", "Log to output.");
10
11int main(int argc, char *argv[]) {
12 aos::InitGoogle(&argc, &argv);
13
14 const std::vector<aos::logger::LogFile> logfiles =
15 aos::logger::SortParts(aos::logger::FindLogs(argc, argv));
16 CHECK(!logfiles.empty());
17 const std::string logger_node = logfiles.at(0).logger_node;
18 bool all_logs_from_same_node = true;
19 for (const aos::logger::LogFile &log : logfiles) {
20 if (log.logger_node != logger_node) {
21 all_logs_from_same_node = false;
22 break;
23 }
24 }
25 std::string replay_node = FLAGS_node;
26 if (replay_node.empty() && all_logs_from_same_node) {
27 LOG(INFO) << "Guessing \"" << logger_node
28 << "\" as node given that --node was not specified.";
29 replay_node = logger_node;
30 }
31
32 std::optional<aos::FlatbufferDetachedBuffer<aos::Configuration>> config;
33
34 aos::logger::LogReader reader(
35 logfiles, config.has_value() ? &config.value().message() : nullptr);
36 aos::SimulatedEventLoopFactory factory(reader.configuration());
37 reader.RegisterWithoutStarting(&factory);
38
39 const aos::Node *node =
40 (replay_node.empty() ||
41 !aos::configuration::MultiNode(reader.configuration()))
42 ? nullptr
43 : aos::configuration::GetNode(reader.configuration(), replay_node);
44
45 std::unique_ptr<aos::EventLoop> can_event_loop;
46 CHECK(!FLAGS_output_path.empty());
47 std::unique_ptr<frc971::can_logger::AscLogger> relogger;
48
49 factory.GetNodeEventLoopFactory(node)->OnStartup([&relogger, &can_event_loop,
50 &reader, node]() {
51 can_event_loop = reader.event_loop_factory()->MakeEventLoop("can", node);
52 relogger = std::make_unique<frc971::can_logger::AscLogger>(
53 can_event_loop.get(), FLAGS_output_path);
54 });
55 reader.event_loop_factory()->Run();
56 reader.Deregister();
57}