blob: b23e8adf1b890325e7b0c6f91928548b77a45e10 [file] [log] [blame]
Henry Speiserc82be542022-04-07 22:05:20 -07001#include "aos/events/logging/log_reader.h"
2#include "aos/events/simulated_event_loop.h"
3#include "aos/init.h"
4#include "frc971/input/joystick_state_generated.h"
5
6// Takes in log file and gives back the Match Type and Match #
7int main(int argc, char **argv) {
8 aos::InitGoogle(&argc, &argv);
9
10 std::vector<std::string> unsorted_logfiles =
11 aos::logger::FindLogs(argc, argv);
12 aos::logger::LogReader reader(aos::logger::SortParts(unsorted_logfiles));
13 reader.Register();
14 const aos::Node *roborio =
15 aos::configuration::GetNode(reader.configuration(), "roborio");
16
17 std::unique_ptr<aos::EventLoop> event_loop =
18 reader.event_loop_factory()->MakeEventLoop("roborio", roborio);
19
20 aos::MatchType match_type = aos::MatchType::kNone;
21 int match_number = 0;
22
23 auto joystick_state_fetcher =
24 event_loop->MakeFetcher<aos::JoystickState>("/roborio/aos");
25
26 event_loop->AddPhasedLoop(
27 [&](int) {
28 // Fetch joystick state if null then don't give type and number
29 if (!joystick_state_fetcher.Fetch()) {
30 return;
31 }
32 match_type = joystick_state_fetcher->match_type();
33 match_number = joystick_state_fetcher->match_number();
34 // Exits if the match type isn't kNone if match type isn't kNone the
35 // match has been found
36 if (match_type != aos::MatchType::kNone) {
37 reader.event_loop_factory()->Exit();
38 return;
39 }
40 },
41 std::chrono::seconds(1));
42
43 reader.event_loop_factory()->Run();
44
45 LOG(INFO) << "Match Type: " << aos::EnumNameMatchType(match_type);
46 LOG(INFO) << "Match #: " << match_number;
47}