blob: cbe7e5063f6ebd428ed5c2a835dff02264cffcb3 [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
Austin Schuhc1609732023-06-26 11:51:28 -070010 aos::logger::LogReader reader(
11 aos::logger::SortParts(aos::logger::FindLogs(argc, argv)));
Henry Speiserc82be542022-04-07 22:05:20 -070012 reader.Register();
13 const aos::Node *roborio =
14 aos::configuration::GetNode(reader.configuration(), "roborio");
15
16 std::unique_ptr<aos::EventLoop> event_loop =
17 reader.event_loop_factory()->MakeEventLoop("roborio", roborio);
18
19 aos::MatchType match_type = aos::MatchType::kNone;
20 int match_number = 0;
21
22 auto joystick_state_fetcher =
23 event_loop->MakeFetcher<aos::JoystickState>("/roborio/aos");
24
25 event_loop->AddPhasedLoop(
26 [&](int) {
27 // Fetch joystick state if null then don't give type and number
28 if (!joystick_state_fetcher.Fetch()) {
29 return;
30 }
31 match_type = joystick_state_fetcher->match_type();
32 match_number = joystick_state_fetcher->match_number();
33 // Exits if the match type isn't kNone if match type isn't kNone the
34 // match has been found
35 if (match_type != aos::MatchType::kNone) {
36 reader.event_loop_factory()->Exit();
37 return;
38 }
39 },
40 std::chrono::seconds(1));
41
42 reader.event_loop_factory()->Run();
43
44 LOG(INFO) << "Match Type: " << aos::EnumNameMatchType(match_type);
45 LOG(INFO) << "Match #: " << match_number;
46}