small safety mechanism for time
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
Robin Müller 2022-03-29 16:59:48 +02:00
parent 0ba2caaf61
commit a8457d7966
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
2 changed files with 14 additions and 2 deletions

View File

@ -173,8 +173,19 @@ void GPSHyperionLinuxController::readGpsDataFromGpsd() {
timeval time = {}; timeval time = {};
time.tv_sec = gpsSet.unixSeconds.value; time.tv_sec = gpsSet.unixSeconds.value;
time.tv_usec = gps->fix.time.tv_nsec / 1000; time.tv_usec = gps->fix.time.tv_nsec / 1000;
std::time_t t = std::time(nullptr);
if (time.tv_sec == t) {
timeIsConstantCounter++;
} else {
timeIsConstantCounter = 0;
}
// If the received time does not change anymore for whatever reason, do not set it here
// to avoid stale times
if(timeIsConstantCounter < 3) {
// Update the system time here for now. NTP seems to be unable to do so for whatever reason // Update the system time here for now. NTP seems to be unable to do so for whatever reason
settimeofday(&time, nullptr); settimeofday(&time, nullptr);
}
Clock::TimeOfDay_t timeOfDay = {}; Clock::TimeOfDay_t timeOfDay = {};
Clock::convertTimevalToTimeOfDay(&time, &timeOfDay); Clock::convertTimevalToTimeOfDay(&time, &timeOfDay);
gpsSet.year = timeOfDay.year; gpsSet.year = timeOfDay.year;

View File

@ -51,6 +51,7 @@ class GPSHyperionLinuxController : public ExtendedControllerBase {
bool modeCommanded = true; bool modeCommanded = true;
gpsmm myGpsmm; gpsmm myGpsmm;
bool debugHyperionGps = false; bool debugHyperionGps = false;
uint32_t timeIsConstantCounter = 0;
void readGpsDataFromGpsd(); void readGpsDataFromGpsd();
}; };