Ravago Jones | 09067de | 2023-03-29 18:44:43 -0700 | [diff] [blame] | 1 | #ifndef FRC971_CAN_LOGGER_ASC_LOGGER_H_ |
| 2 | #define FRC971_CAN_LOGGER_ASC_LOGGER_H_ |
| 3 | |
| 4 | #include <iomanip> |
| 5 | #include <iostream> |
| 6 | |
Austin Schuh | 99f7c6a | 2024-06-25 22:07:44 -0700 | [diff] [blame] | 7 | #include "absl/flags/flag.h" |
| 8 | #include "absl/log/check.h" |
| 9 | #include "absl/log/log.h" |
Ravago Jones | 09067de | 2023-03-29 18:44:43 -0700 | [diff] [blame] | 10 | |
Philipp Schrader | 790cb54 | 2023-07-05 21:06:52 -0700 | [diff] [blame] | 11 | #include "aos/events/event_loop.h" |
| 12 | #include "frc971/can_logger/can_logging_generated.h" |
| 13 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 14 | namespace frc971::can_logger { |
Ravago Jones | 09067de | 2023-03-29 18:44:43 -0700 | [diff] [blame] | 15 | |
| 16 | class AscLogger { |
| 17 | public: |
| 18 | AscLogger(aos::EventLoop *event_loop, const std::string &filename); |
| 19 | |
| 20 | private: |
| 21 | void HandleFrame(const CanFrame &frame); |
| 22 | |
| 23 | // This implementation attempts to duplicate the output of can-utils/log2asc |
| 24 | void WriteFrame(std::ostream &file, const CanFrame &frame); |
| 25 | |
| 26 | static void WriteHeader(std::ostream &file, |
| 27 | aos::realtime_clock::time_point start_time); |
| 28 | |
James Kuszmaul | 22248e9 | 2024-02-23 16:46:51 -0800 | [diff] [blame] | 29 | std::optional<aos::realtime_clock::time_point> first_frame_realtime_; |
Ravago Jones | 09067de | 2023-03-29 18:44:43 -0700 | [diff] [blame] | 30 | |
| 31 | std::ofstream output_; |
| 32 | |
| 33 | aos::EventLoop *event_loop_; |
| 34 | }; |
| 35 | |
Stephan Pleines | d99b1ee | 2024-02-02 20:56:44 -0800 | [diff] [blame] | 36 | } // namespace frc971::can_logger |
Ravago Jones | 09067de | 2023-03-29 18:44:43 -0700 | [diff] [blame] | 37 | |
| 38 | #endif // FRC971_CAN_LOGGER_ASC_LOGGER_H_ |