43 lines
937 B
C++
43 lines
937 B
C++
#include "fsfw/timemanager/Clock.h"
|
|
|
|
#include <cstdlib>
|
|
#include <ctime>
|
|
|
|
#include "FreeRTOS.h"
|
|
#include "fsfw/globalfunctions/timevalOperations.h"
|
|
#include "fsfw/osal/freertos/Timekeeper.h"
|
|
#include "task.h"
|
|
|
|
// TODO sanitize input?
|
|
// TODO much of this code can be reused for tick-only systems
|
|
|
|
ReturnValue_t Clock::setClock(const timeval* time) {
|
|
timeval uptime = getUptime();
|
|
|
|
timeval offset = *time - uptime;
|
|
|
|
Timekeeper::instance()->setOffset(offset);
|
|
|
|
return returnvalue::OK;
|
|
}
|
|
|
|
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
|
timeval uptime = getUptime();
|
|
|
|
timeval offset = Timekeeper::instance()->getOffset();
|
|
|
|
*time = offset + uptime;
|
|
|
|
return returnvalue::OK;
|
|
}
|
|
|
|
timeval Clock::getUptime() {
|
|
TickType_t ticksSinceStart = xTaskGetTickCount();
|
|
return Timekeeper::ticksToTimeval(ticksSinceStart);
|
|
}
|
|
|
|
// uint32_t Clock::getUptimeSeconds() {
|
|
// timeval uptime = getUptime();
|
|
// return uptime.tv_sec;
|
|
// }
|