Merge pull request 'bugfix and changelog for Linux getUptime' (#745) from eive/fsfw:important_bugfix_linux_get_uptime into development

Reviewed-on: fsfw/fsfw#745
This commit is contained in:
Ulrich Mohr 2023-05-08 14:29:55 +02:00
commit f84431e965
2 changed files with 8 additions and 4 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Fixes ## Fixes
- Linux OSAL `getUptime` fix: Check validity of `/proc/uptime` file before reading uptime.
- PUS Health Service: Size check for set health command. - PUS Health Service: Size check for set health command.
- PUS Health Service: Perform operation completion for announce health command. - PUS Health Service: Perform operation completion for announce health command.

View File

@ -76,15 +76,18 @@ timeval Clock::getUptime() {
} }
ReturnValue_t Clock::getUptime(timeval* uptime) { ReturnValue_t Clock::getUptime(timeval* uptime) {
// TODO This is not posix compatible and delivers only seconds precision
// Linux specific file read but more precise.
double uptimeSeconds; double uptimeSeconds;
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds) { std::ifstream ifile("/proc/uptime");
if (ifile.bad()) {
return returnvalue::FAILED;
}
if (ifile >> uptimeSeconds) {
uptime->tv_sec = uptimeSeconds; uptime->tv_sec = uptimeSeconds;
uptime->tv_usec = uptimeSeconds * (double)1e6 - (uptime->tv_sec * 1e6); uptime->tv_usec = uptimeSeconds * (double)1e6 - (uptime->tv_sec * 1e6);
}
return returnvalue::OK; return returnvalue::OK;
} }
return returnvalue::FAILED;
}
// Wait for new FSFW Clock function delivering seconds uptime. // Wait for new FSFW Clock function delivering seconds uptime.
// uint32_t Clock::getUptimeSeconds() { // uint32_t Clock::getUptimeSeconds() {