From 740167ce99d53e35102cfb9a29caedc48ea0fb0c Mon Sep 17 00:00:00 2001 From: meggert Date: Wed, 11 Oct 2023 14:30:57 +0200 Subject: [PATCH] monotonic for pwr ctrl --- mission/controller/PowerController.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mission/controller/PowerController.cpp b/mission/controller/PowerController.cpp index 7b7db9e8..202e9906 100644 --- a/mission/controller/PowerController.cpp +++ b/mission/controller/PowerController.cpp @@ -156,7 +156,7 @@ ReturnValue_t PowerController::checkModeCommand(Mode_t mode, Submode_t submode, void PowerController::calculateStateOfCharge() { // get time - Clock::getClock_timeval(&now); + Clock::getClockMonotonic(&now); // update EPS HK values ReturnValue_t result = updateEpsData(); @@ -285,7 +285,12 @@ ReturnValue_t PowerController::calculateOpenCircuitVoltageCharge() { } ReturnValue_t PowerController::calculateCoulombCounterCharge() { - double timeDiff = timevalOperations::toDouble(now - oldTime); + double timeDiff = 0.0; + if (timevalOperations::toDouble(oldTime) != 0) { + timeDiff = timevalOperations::toDouble(now - oldTime); + } else { + return returnvalue::FAILED; + } if (timeDiff > maxAllowedTimeDiff) { // should not be a permanent state so no spam protection required triggerEvent(power::TIMEDELTA_OUT_OF_BOUNDS, static_cast(timeDiff * 10));