prep for leap seconds
Some checks failed
EIVE/eive-obsw/pipeline/pr-main There was a failure building this commit

This commit is contained in:
2024-03-05 09:06:48 +01:00
parent cda2a9df33
commit 2a2a173ebd
4 changed files with 70 additions and 0 deletions

View File

@@ -480,6 +480,13 @@ ReturnValue_t CoreController::executeAction(ActionId_t actionId, MessageQueueId_
successRecipient = commandedBy;
return returnvalue::OK;
}
case (UPDATE_LEAP_SECONDS): {
ReturnValue_t result = actionUpdateLeapSeconds();
if (result != returnvalue::OK) {
return result;
}
return HasActionsIF::EXECUTION_FINISHED;
}
default: {
return HasActionsIF::INVALID_ACTION_ID;
}
@@ -2066,9 +2073,60 @@ ReturnValue_t CoreController::backupTimeFileHandler() {
return returnvalue::OK;
}
void CoreController::initLeapSeconds() {
ReturnValue_t result = initLeapSecondsFromFile();
if (result != returnvalue::OK) {
Clock::setLeapSeconds(config::LEAP_SECONDS);
writeLeapSecondsToFile(config::LEAP_SECONDS);
}
}
ReturnValue_t CoreController::initLeapSecondsFromFile() {
std::string fileName = currMntPrefix + LEAP_SECONDS_FILE;
std::error_code e;
if (sdcMan->isSdCardUsable(std::nullopt) and std::filesystem::exists(fileName, e)) {
std::ifstream leapSecondsFile(fileName);
std::string nextWord;
std::getline(leapSecondsFile, nextWord);
std::istringstream iss(nextWord);
iss >> nextWord;
if (iss.bad() or nextWord != "LEAP") {
return returnvalue::FAILED;
}
iss >> nextWord;
if (iss.bad() or nextWord != "SECONDS:") {
return returnvalue::FAILED;
}
iss >> nextWord;
uint16_t leapSeconds = 0;
size_t checkPtr;
leapSeconds = std::stoi(nextWord.c_str(), &checkPtr, 10);
if (iss.bad() or *checkPtr) {
return returnvalue::FAILED;
}
Clock::setLeapSeconds(leapSeconds);
return returnvalue::OK;
}
return returnvalue::FAILED;
};
ReturnValue_t CoreController::writeLeapSecondsToFile(const uint16_t leapSeconds) {
std::string fileName = currMntPrefix + LEAP_SECONDS_FILE;
if (sdcMan->isSdCardUsable(std::nullopt)) {
std::ofstream leapSecondsFile(fileName.c_str(), std::ofstream::out | std::ofstream::trunc);
if (leapSecondsFile.is_open()) {
leapSecondsFile << "LEAP SECONDS: " << leapSeconds << std::endl;
}
}
return returnvalue::FAILED;
};
ReturnValue_t CoreController::actionUpdateLeapSeconds() { ; }
ReturnValue_t CoreController::initClockFromTimeFile() {
using namespace GpsHyperion;
using namespace std;
std::string fileName = currMntPrefix + BACKUP_TIME_FILE;
std::error_code e;
if (sdcMan->isSdCardUsable(std::nullopt) and std::filesystem::exists(fileName, e) and