blob: 7ac8b5bde0657f87e7cb39544e5218ef7497e30e [file] [log] [blame]
Ravago Jones09067de2023-03-29 18:44:43 -07001#ifndef FRC971_CAN_LOGGER_ASC_LOGGER_H_
2#define FRC971_CAN_LOGGER_ASC_LOGGER_H_
3
4#include <iomanip>
5#include <iostream>
6
Austin Schuh99f7c6a2024-06-25 22:07:44 -07007#include "absl/flags/flag.h"
8#include "absl/log/check.h"
9#include "absl/log/log.h"
Ravago Jones09067de2023-03-29 18:44:43 -070010
Philipp Schrader790cb542023-07-05 21:06:52 -070011#include "aos/events/event_loop.h"
12#include "frc971/can_logger/can_logging_generated.h"
13
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080014namespace frc971::can_logger {
Ravago Jones09067de2023-03-29 18:44:43 -070015
16class 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 Kuszmaul22248e92024-02-23 16:46:51 -080029 std::optional<aos::realtime_clock::time_point> first_frame_realtime_;
Ravago Jones09067de2023-03-29 18:44:43 -070030
31 std::ofstream output_;
32
33 aos::EventLoop *event_loop_;
34};
35
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080036} // namespace frc971::can_logger
Ravago Jones09067de2023-03-29 18:44:43 -070037
38#endif // FRC971_CAN_LOGGER_ASC_LOGGER_H_