[wpilib] DataLogManager: Use system time valid function (#5697)

This commit is contained in:
Peter Johnson
2023-09-30 09:24:06 -07:00
committed by GitHub
parent d404af5f24
commit c92bad52cb
2 changed files with 14 additions and 13 deletions

View File

@@ -22,6 +22,7 @@
#include "frc/DriverStation.h"
#include "frc/Filesystem.h"
#include "frc/RobotBase.h"
#include "frc/RobotController.h"
using namespace frc;
@@ -203,12 +204,10 @@ void Thread::Main() {
} else {
dsAttachCount = 0;
}
if (dsAttachCount > 300) { // 6 seconds
std::time_t now = std::time(nullptr);
auto tm = std::gmtime(&now);
if (tm->tm_year > 100) {
// assume local clock is now synchronized to DS, so rename based on
// local time
if (dsAttachCount > 50) { // 1 second
if (RobotController::IsSystemTimeValid()) {
std::time_t now = std::time(nullptr);
auto tm = std::gmtime(&now);
m_log.SetFilename(fmt::format("FRC_{:%Y%m%d_%H%M%S}.wpilog", *tm));
dsRenamed = true;
} else {
@@ -260,7 +259,9 @@ void Thread::Main() {
++sysTimeCount;
if (sysTimeCount >= 250) {
sysTimeCount = 0;
sysTimeEntry.Append(wpi::GetSystemTime(), wpi::Now());
if (RobotController::IsSystemTimeValid()) {
sysTimeEntry.Append(wpi::GetSystemTime(), wpi::Now());
}
}
}
DriverStation::RemoveRefreshedDataEventHandle(newDataEvent.GetHandle());

View File

@@ -331,11 +331,9 @@ public final class DataLogManager {
} else {
dsAttachCount = 0;
}
if (dsAttachCount > 300) { // 6 seconds
LocalDateTime now = LocalDateTime.now(m_utc);
if (now.getYear() > 2000) {
// assume local clock is now synchronized to DS, so rename based on
// local time
if (dsAttachCount > 50) { // 1 second
if (RobotController.isSystemTimeValid()) {
LocalDateTime now = LocalDateTime.now(m_utc);
m_log.setFilename("FRC_" + m_timeFormatter.format(now) + ".wpilog");
dsRenamed = true;
} else {
@@ -391,7 +389,9 @@ public final class DataLogManager {
sysTimeCount++;
if (sysTimeCount >= 250) {
sysTimeCount = 0;
sysTimeEntry.append(WPIUtilJNI.getSystemTime(), WPIUtilJNI.now());
if (RobotController.isSystemTimeValid()) {
sysTimeEntry.append(WPIUtilJNI.getSystemTime(), WPIUtilJNI.now());
}
}
}
newDataEvent.close();