Account for socketcan providing realtime timestamps
We are getting realtime timestamps back, but were treating them as
monotonic times. Fix that.
Change-Id: Ib92ced05870dcfa7a476ce2509b28eb307bda5ac
Signed-off-by: James Kuszmaul <jabukuszmaul+collab@gmail.com>
diff --git a/frc971/can_logger/asc_logger.cc b/frc971/can_logger/asc_logger.cc
index 6848938..5282d13 100644
--- a/frc971/can_logger/asc_logger.cc
+++ b/frc971/can_logger/asc_logger.cc
@@ -12,11 +12,11 @@
}
void AscLogger::HandleFrame(const CanFrame &frame) {
- if (!first_frame_monotonic_) {
- aos::monotonic_clock::time_point time(
- std::chrono::nanoseconds(frame.monotonic_timestamp_ns()));
+ if (!first_frame_realtime_) {
+ aos::realtime_clock::time_point time(
+ std::chrono::nanoseconds(frame.realtime_timestamp_ns()));
- first_frame_monotonic_ = time;
+ first_frame_realtime_ = time;
WriteHeader(output_, event_loop_->realtime_now());
}
@@ -60,11 +60,11 @@
} // namespace
void AscLogger::WriteFrame(std::ostream &file, const CanFrame &frame) {
- aos::monotonic_clock::time_point frame_timestamp(
- std::chrono::nanoseconds(frame.monotonic_timestamp_ns()));
+ aos::realtime_clock::time_point frame_timestamp(
+ std::chrono::nanoseconds(frame.realtime_timestamp_ns()));
std::chrono::duration<double> time(frame_timestamp -
- first_frame_monotonic_.value());
+ first_frame_realtime_.value());
// TODO: maybe this should not be hardcoded
const int device_id = 1;
diff --git a/frc971/can_logger/asc_logger.h b/frc971/can_logger/asc_logger.h
index 2be2eb2..e7d4e74 100644
--- a/frc971/can_logger/asc_logger.h
+++ b/frc971/can_logger/asc_logger.h
@@ -25,7 +25,7 @@
static void WriteHeader(std::ostream &file,
aos::realtime_clock::time_point start_time);
- std::optional<aos::monotonic_clock::time_point> first_frame_monotonic_;
+ std::optional<aos::realtime_clock::time_point> first_frame_realtime_;
std::ofstream output_;
diff --git a/frc971/can_logger/can_logger.cc b/frc971/can_logger/can_logger.cc
index cfc3dd8..7d33464 100644
--- a/frc971/can_logger/can_logger.cc
+++ b/frc971/can_logger/can_logger.cc
@@ -75,8 +75,8 @@
can_frame_builder.add_can_id(frame.can_id);
can_frame_builder.add_flags(frame.flags);
can_frame_builder.add_data(frame_data);
- can_frame_builder.add_monotonic_timestamp_ns(
- static_cast<std::chrono::nanoseconds>(
+ can_frame_builder.add_realtime_timestamp_ns(
+ std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::seconds(tv.tv_sec) +
std::chrono::microseconds(tv.tv_usec))
.count());
diff --git a/frc971/can_logger/can_logging.fbs b/frc971/can_logger/can_logging.fbs
index ba60241..c7a82f2 100644
--- a/frc971/can_logger/can_logging.fbs
+++ b/frc971/can_logger/can_logging.fbs
@@ -7,7 +7,7 @@
// The body of the CAN frame up to 64 bytes long.
data:[ubyte] (id: 1);
// The hardware timestamp of when the frame came in
- monotonic_timestamp_ns:uint64 (id: 2);
+ realtime_timestamp_ns:uint64 (id: 2);
// Additional flags for CAN FD
flags: ubyte (id: 3);
}