clocks suck a little less
This commit is contained in:
parent
123c81777a
commit
7426e10f82
@ -321,8 +321,7 @@ void DeviceHandlerBase::doStateMachine() {
|
|||||||
if (mode != currentMode) {
|
if (mode != currentMode) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint32_t currentUptime;
|
uint32_t currentUptime = Clock::getUptime_ms();
|
||||||
Clock::getUptime(¤tUptime);
|
|
||||||
if (currentUptime - timeoutStart >= childTransitionDelay) {
|
if (currentUptime - timeoutStart >= childTransitionDelay) {
|
||||||
#if FSFW_VERBOSE_LEVEL >= 1 && FSFW_OBJ_EVENT_TRANSLATION == 0
|
#if FSFW_VERBOSE_LEVEL >= 1 && FSFW_OBJ_EVENT_TRANSLATION == 0
|
||||||
char printout[60];
|
char printout[60];
|
||||||
@ -346,8 +345,7 @@ void DeviceHandlerBase::doStateMachine() {
|
|||||||
setMode(_MODE_WAIT_ON);
|
setMode(_MODE_WAIT_ON);
|
||||||
break;
|
break;
|
||||||
case _MODE_WAIT_ON: {
|
case _MODE_WAIT_ON: {
|
||||||
uint32_t currentUptime;
|
uint32_t currentUptime = Clock::getUptime_ms();
|
||||||
Clock::getUptime(¤tUptime);
|
|
||||||
if (powerSwitcher != nullptr and
|
if (powerSwitcher != nullptr and
|
||||||
currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
currentUptime - timeoutStart >= powerSwitcher->getSwitchDelayMs()) {
|
||||||
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT, 0);
|
triggerEvent(MODE_TRANSITION_FAILED, PowerSwitchIF::SWITCH_TIMEOUT, 0);
|
||||||
@ -366,8 +364,7 @@ void DeviceHandlerBase::doStateMachine() {
|
|||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case _MODE_WAIT_OFF: {
|
case _MODE_WAIT_OFF: {
|
||||||
uint32_t currentUptime;
|
uint32_t currentUptime = Clock::getUptime_ms();
|
||||||
Clock::getUptime(¤tUptime);
|
|
||||||
|
|
||||||
if (powerSwitcher == nullptr) {
|
if (powerSwitcher == nullptr) {
|
||||||
setMode(MODE_OFF);
|
setMode(MODE_OFF);
|
||||||
@ -577,7 +574,7 @@ void DeviceHandlerBase::setMode(Mode_t newMode, uint8_t newSubmode) {
|
|||||||
modeHelper.modeChanged(newMode, newSubmode);
|
modeHelper.modeChanged(newMode, newSubmode);
|
||||||
announceMode(false);
|
announceMode(false);
|
||||||
}
|
}
|
||||||
Clock::getUptime(&timeoutStart);
|
timeoutStart = Clock::getUptime_ms();
|
||||||
|
|
||||||
if (mode == MODE_OFF and thermalSet != nullptr) {
|
if (mode == MODE_OFF and thermalSet != nullptr) {
|
||||||
ReturnValue_t result = thermalSet->read();
|
ReturnValue_t result = thermalSet->read();
|
||||||
|
@ -37,20 +37,8 @@ timeval Clock::getUptime() {
|
|||||||
timeval uptime{0,0};
|
timeval uptime{0,0};
|
||||||
double uptimeSeconds;
|
double uptimeSeconds;
|
||||||
if (std::ifstream("/proc/uptime", std::ios::in) >> uptimeSeconds) {
|
if (std::ifstream("/proc/uptime", std::ios::in) >> 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 uptime;
|
return uptime;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for new FSFW Clock function delivering seconds uptime.
|
|
||||||
// uint32_t Clock::getUptimeSeconds() {
|
|
||||||
// //TODO This is not posix compatible and delivers only seconds precision
|
|
||||||
// struct sysinfo sysInfo;
|
|
||||||
// int result = sysinfo(&sysInfo);
|
|
||||||
// if(result != 0){
|
|
||||||
// return returnvalue::FAILED;
|
|
||||||
// }
|
|
||||||
// return sysInfo.uptime;
|
|
||||||
//}
|
|
||||||
|
|
@ -6,20 +6,21 @@
|
|||||||
#include "fsfw/ipc/MutexGuard.h"
|
#include "fsfw/ipc/MutexGuard.h"
|
||||||
#include "fsfw/osal/rtems/RtemsBasic.h"
|
#include "fsfw/osal/rtems/RtemsBasic.h"
|
||||||
|
|
||||||
uint32_t Clock::getTicksPerSecond(void) {
|
|
||||||
rtems_interval ticks_per_second = rtems_clock_get_ticks_per_second();
|
|
||||||
return static_cast<uint32_t>(ticks_per_second);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
|
ReturnValue_t Clock::setClock(const timeval* time) {
|
||||||
|
TimeOfDay_t time_tod;
|
||||||
|
ReturnValue_t result = convertTimevalToTimeOfDay(time, &time_tod);
|
||||||
|
if (result != returnvalue::OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
rtems_time_of_day timeRtems;
|
rtems_time_of_day timeRtems;
|
||||||
timeRtems.year = time->year;
|
timeRtems.year = time_tod.year;
|
||||||
timeRtems.month = time->month;
|
timeRtems.month = time_tod.month;
|
||||||
timeRtems.day = time->day;
|
timeRtems.day = time_tod.day;
|
||||||
timeRtems.hour = time->hour;
|
timeRtems.hour = time_tod.hour;
|
||||||
timeRtems.minute = time->minute;
|
timeRtems.minute = time_tod.minute;
|
||||||
timeRtems.second = time->second;
|
timeRtems.second = time_tod.second;
|
||||||
timeRtems.ticks = time->usecond * getTicksPerSecond() / 1e6;
|
timeRtems.ticks = static_cast<uint64_t>(time_tod.usecond) * rtems_clock_get_ticks_per_second() / 1e6;
|
||||||
rtems_status_code status = rtems_clock_set(&timeRtems);
|
rtems_status_code status = rtems_clock_set(&timeRtems);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case RTEMS_SUCCESSFUL:
|
case RTEMS_SUCCESSFUL:
|
||||||
@ -33,15 +34,6 @@ ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t Clock::setClock(const timeval* time) {
|
|
||||||
TimeOfDay_t time_tod;
|
|
||||||
ReturnValue_t result = convertTimevalToTimeOfDay(time, &time_tod);
|
|
||||||
if (result != returnvalue::OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return setClock(&time_tod);
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
||||||
// Callable from ISR
|
// Callable from ISR
|
||||||
rtems_status_code status = rtems_clock_get_tod_timeval(time);
|
rtems_status_code status = rtems_clock_get_tod_timeval(time);
|
||||||
@ -55,36 +47,13 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t Clock::getUptime(timeval* uptime) {
|
timeval Clock::getUptime() {
|
||||||
// According to docs.rtems.org for rtems 5 this method is more accurate than
|
// According to docs.rtems.org for rtems 5 this method is more accurate than
|
||||||
// rtems_clock_get_ticks_since_boot
|
// rtems_clock_get_ticks_since_boot
|
||||||
|
timeval time_timeval;
|
||||||
timespec time;
|
timespec time;
|
||||||
rtems_status_code status = rtems_clock_get_uptime(&time);
|
rtems_status_code status = rtems_clock_get_uptime(&time);
|
||||||
uptime->tv_sec = time.tv_sec;
|
time_timeval.tv_sec = time.tv_sec;
|
||||||
uptime->tv_usec = time.tv_nsec / 1000;
|
time_timeval.tv_usec = time.tv_nsec / 1000;
|
||||||
switch (status) {
|
return time_timeval;
|
||||||
case RTEMS_SUCCESSFUL:
|
}
|
||||||
return returnvalue::OK;
|
|
||||||
default:
|
|
||||||
return returnvalue::FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) {
|
|
||||||
// 32bit counter overflows after 50 days
|
|
||||||
uint64_t uptime = rtems_clock_get_uptime_nanoseconds() / 1e6;
|
|
||||||
*uptimeMs = uptime & 0xffffffff;
|
|
||||||
return returnvalue::OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
|
|
||||||
timeval temp_time;
|
|
||||||
rtems_status_code returnValue = rtems_clock_get_tod_timeval(&temp_time);
|
|
||||||
*time = ((uint64_t)temp_time.tv_sec * 1000000) + temp_time.tv_usec;
|
|
||||||
switch (returnValue) {
|
|
||||||
case RTEMS_SUCCESSFUL:
|
|
||||||
return returnvalue::OK;
|
|
||||||
default:
|
|
||||||
return returnvalue::FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
@ -33,13 +33,12 @@ ReturnValue_t Service9TimeManagement::setTime() {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t formerUptime;
|
// TODO maybe switch to getClock_usecs to report more meaningful data
|
||||||
Clock::getUptime(&formerUptime);
|
uint32_t formerUptime = Clock::getUptime_ms();
|
||||||
result = Clock::setClock(&timeToSet);
|
result = Clock::setClock(&timeToSet);
|
||||||
|
|
||||||
if (result == returnvalue::OK) {
|
if (result == returnvalue::OK) {
|
||||||
uint32_t newUptime;
|
uint32_t newUptime = Clock::getUptime_ms();
|
||||||
Clock::getUptime(&newUptime);
|
|
||||||
triggerEvent(CLOCK_SET, newUptime, formerUptime);
|
triggerEvent(CLOCK_SET, newUptime, formerUptime);
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,11 +91,10 @@ void Subsystem::performChildOperation() {
|
|||||||
}
|
}
|
||||||
if (currentSequenceIterator->getWaitSeconds() != 0) {
|
if (currentSequenceIterator->getWaitSeconds() != 0) {
|
||||||
if (uptimeStartTable == 0) {
|
if (uptimeStartTable == 0) {
|
||||||
Clock::getUptime(&uptimeStartTable);
|
uptimeStartTable = Clock::getUptime_ms();
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
uint32_t uptimeNow;
|
uint32_t uptimeNow = Clock::getUptime_ms();
|
||||||
Clock::getUptime(&uptimeNow);
|
|
||||||
if ((uptimeNow - uptimeStartTable) < (currentSequenceIterator->getWaitSeconds() * 1000)) {
|
if ((uptimeNow - uptimeStartTable) < (currentSequenceIterator->getWaitSeconds() * 1000)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -198,10 +198,9 @@ void Heater::setSwitch(uint8_t number, ReturnValue_t state, uint32_t* uptimeOfSw
|
|||||||
} else {
|
} else {
|
||||||
if ((*uptimeOfSwitching == INVALID_UPTIME)) {
|
if ((*uptimeOfSwitching == INVALID_UPTIME)) {
|
||||||
powerSwitcher->sendSwitchCommand(number, state);
|
powerSwitcher->sendSwitchCommand(number, state);
|
||||||
Clock::getUptime(uptimeOfSwitching);
|
*uptimeOfSwitching = Clock::getUptime_ms();
|
||||||
} else {
|
} else {
|
||||||
uint32_t currentUptime;
|
uint32_t currentUptime = Clock::getUptime_ms();
|
||||||
Clock::getUptime(¤tUptime);
|
|
||||||
if (currentUptime - *uptimeOfSwitching > powerSwitcher->getSwitchDelayMs()) {
|
if (currentUptime - *uptimeOfSwitching > powerSwitcher->getSwitchDelayMs()) {
|
||||||
*uptimeOfSwitching = INVALID_UPTIME;
|
*uptimeOfSwitching = INVALID_UPTIME;
|
||||||
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
if (healthHelper.healthTable->isHealthy(getObjectId())) {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
#include "fsfw/ipc/MutexGuard.h"
|
#include "fsfw/ipc/MutexGuard.h"
|
||||||
#include "fsfw/timemanager/Clock.h"
|
#include "fsfw/timemanager/Clock.h"
|
||||||
@ -91,15 +92,28 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval*
|
|||||||
|
|
||||||
time_tm.tm_isdst = 0;
|
time_tm.tm_isdst = 0;
|
||||||
|
|
||||||
#ifdef PLATFORM_WIN
|
// Windows:
|
||||||
time_t seconds = _mkgmtime(&time_tm);
|
// time_t seconds = _mkgmtime(&time_tm);
|
||||||
#else
|
// Glibc:
|
||||||
time_t seconds = timegm(&time_tm);
|
// time_t seconds = timegm(&time_tm);
|
||||||
#endif
|
// Portable (?)
|
||||||
|
char* tz;
|
||||||
|
tz = getenv("TZ");
|
||||||
|
setenv("TZ", "", 1);
|
||||||
|
tzset();
|
||||||
|
time_t seconds = mktime(&time_tm);
|
||||||
|
if (tz)
|
||||||
|
setenv("TZ", tz, 1);
|
||||||
|
else
|
||||||
|
unsetenv("TZ");
|
||||||
|
tzset();
|
||||||
to->tv_sec = seconds;
|
to->tv_sec = seconds;
|
||||||
to->tv_usec = from->usecond;
|
to->tv_usec = from->usecond;
|
||||||
|
|
||||||
|
if (seconds == (time_t) -1) {
|
||||||
|
return returnvalue::FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,6 +166,6 @@ ReturnValue_t Clock::setClock(const TimeOfDay_t* time) {
|
|||||||
}
|
}
|
||||||
uint32_t Clock::getUptime_ms() {
|
uint32_t Clock::getUptime_ms() {
|
||||||
timeval uptime = getUptime();
|
timeval uptime = getUptime();
|
||||||
//TODO verify that overflow is correct
|
// TODO verify that overflow is correct
|
||||||
return uptime.tv_sec * 1e3 + uptime.tv_usec / 1e3;
|
return uptime.tv_sec * 1e3 + uptime.tv_usec / 1e3;
|
||||||
}
|
}
|
@ -7,9 +7,9 @@ Countdown::Countdown(uint32_t initialTimeout) : timeout(initialTimeout) {
|
|||||||
Countdown::~Countdown() {}
|
Countdown::~Countdown() {}
|
||||||
|
|
||||||
ReturnValue_t Countdown::setTimeout(uint32_t milliseconds) {
|
ReturnValue_t Countdown::setTimeout(uint32_t milliseconds) {
|
||||||
ReturnValue_t returnValue = Clock::getUptime(&startTime);
|
startTime = Clock::getUptime_ms();
|
||||||
timeout = milliseconds;
|
timeout = milliseconds;
|
||||||
return returnValue;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Countdown::hasTimedOut() const {
|
bool Countdown::hasTimedOut() const {
|
||||||
@ -39,7 +39,5 @@ uint32_t Countdown::getRemainingMillis() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t Countdown::getCurrentTime() const {
|
uint32_t Countdown::getCurrentTime() const {
|
||||||
uint32_t currentTime;
|
return Clock::getUptime_ms();
|
||||||
Clock::getUptime(¤tTime);
|
|
||||||
return currentTime;
|
|
||||||
}
|
}
|
||||||
|
@ -348,7 +348,7 @@ void CommandingServiceBase::startExecution(store_address_t storeId, CommandMapIt
|
|||||||
sendResult = commandQueue->sendMessage(iter.value->first, &command);
|
sendResult = commandQueue->sendMessage(iter.value->first, &command);
|
||||||
}
|
}
|
||||||
if (sendResult == returnvalue::OK) {
|
if (sendResult == returnvalue::OK) {
|
||||||
Clock::getUptime(&iter->second.uptimeOfStart);
|
iter->second.uptimeOfStart = Clock::getUptime_ms();
|
||||||
iter->second.step = 0;
|
iter->second.step = 0;
|
||||||
iter->second.subservice = tcReader.getSubService();
|
iter->second.subservice = tcReader.getSubService();
|
||||||
iter->second.command = command.getCommand();
|
iter->second.command = command.getCommand();
|
||||||
@ -434,8 +434,7 @@ inline void CommandingServiceBase::doPeriodicOperation() {}
|
|||||||
MessageQueueId_t CommandingServiceBase::getCommandQueue() { return commandQueue->getId(); }
|
MessageQueueId_t CommandingServiceBase::getCommandQueue() { return commandQueue->getId(); }
|
||||||
|
|
||||||
void CommandingServiceBase::checkTimeout() {
|
void CommandingServiceBase::checkTimeout() {
|
||||||
uint32_t uptime;
|
uint32_t uptime = Clock::getUptime_ms();
|
||||||
Clock::getUptime(&uptime);
|
|
||||||
CommandMapIter iter;
|
CommandMapIter iter;
|
||||||
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
|
for (iter = commandMap.begin(); iter != commandMap.end(); ++iter) {
|
||||||
if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
|
if ((iter->second.uptimeOfStart + (timeoutSeconds * 1000)) < uptime) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user