Maxwell Henderson | 7643e4c | 2024-03-11 20:43:18 -0700 | [diff] [blame^] | 1 | #include <fstream> |
| 2 | |
| 3 | #include "gflags/gflags.h" |
| 4 | #include "glog/logging.h" |
| 5 | |
| 6 | #include "aos/events/logging/log_reader.h" |
| 7 | #include "aos/events/simulated_event_loop.h" |
| 8 | #include "aos/init.h" |
| 9 | #include "frc971/wpilib/pdp_values_generated.h" |
| 10 | |
| 11 | DEFINE_string(output_path, "/tmp/pdp_values.csv", ""); |
| 12 | |
| 13 | int main(int argc, char **argv) { |
| 14 | aos::InitGoogle(&argc, &argv); |
| 15 | |
| 16 | aos::logger::LogReader reader( |
| 17 | aos::logger::SortParts(aos::logger::FindLogs(argc, argv))); |
| 18 | |
| 19 | aos::SimulatedEventLoopFactory event_loop_factory(reader.configuration()); |
| 20 | |
| 21 | reader.RegisterWithoutStarting(&event_loop_factory); |
| 22 | |
| 23 | const aos::Node *roborio = |
| 24 | aos::configuration::GetNode(reader.configuration(), "roborio"); |
| 25 | |
| 26 | std::unique_ptr<aos::EventLoop> event_loop = |
| 27 | event_loop_factory.MakeEventLoop("roborio", roborio); |
| 28 | |
| 29 | std::ofstream file_stream; |
| 30 | file_stream.open(FLAGS_output_path); |
| 31 | file_stream << "timestamp,currents,voltage\n"; |
| 32 | |
| 33 | event_loop->SkipAosLog(); |
| 34 | event_loop->MakeWatcher( |
| 35 | "/roborio/aos", |
| 36 | [&file_stream, &event_loop](const frc971::PDPValues &pdp_values) { |
| 37 | file_stream << event_loop->context().monotonic_event_time << "," |
| 38 | << "["; |
| 39 | |
| 40 | for (uint i = 0; i < pdp_values.currents()->size(); i++) { |
| 41 | file_stream << pdp_values.currents()->Get(i); |
| 42 | if (i != pdp_values.currents()->size() - 1) { |
| 43 | file_stream << ", "; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | file_stream << "]," << pdp_values.voltage() << "\n"; |
| 48 | }); |
| 49 | |
| 50 | event_loop_factory.Run(); |
| 51 | |
| 52 | reader.Deregister(); |
| 53 | |
| 54 | file_stream.close(); |
| 55 | |
| 56 | return 0; |
| 57 | } |