Moved Code to own cpp
This commit is contained in:
parent
21d213f35f
commit
ecb03b8a6d
@ -5,4 +5,5 @@ target_sources(${LIB_FSFW_NAME}
|
|||||||
Stopwatch.cpp
|
Stopwatch.cpp
|
||||||
TimeMessage.cpp
|
TimeMessage.cpp
|
||||||
TimeStamper.cpp
|
TimeStamper.cpp
|
||||||
|
ClockCommon.cpp
|
||||||
)
|
)
|
||||||
|
@ -133,28 +133,7 @@ public:
|
|||||||
* - @c RETURN_OK on success
|
* - @c RETURN_OK on success
|
||||||
* - @c RETURN_FAILED if leapSeconds are not set
|
* - @c RETURN_FAILED if leapSeconds are not set
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval *tt) {
|
static ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval *tt);
|
||||||
if (timeMutex == nullptr) {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t leapSeconds;
|
|
||||||
ReturnValue_t result = getLeapSeconds(&leapSeconds);
|
|
||||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
timeval leapSeconds_timeval = { 0, 0 };
|
|
||||||
leapSeconds_timeval.tv_sec = leapSeconds;
|
|
||||||
|
|
||||||
//initial offset between UTC and TAI
|
|
||||||
timeval UTCtoTAI1972 = { 10, 0 };
|
|
||||||
|
|
||||||
timeval TAItoTT = { 32, 184000 };
|
|
||||||
|
|
||||||
*tt = utc + leapSeconds_timeval + UTCtoTAI1972 + TAItoTT;
|
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Leap Seconds since 1972
|
* Set the Leap Seconds since 1972
|
||||||
@ -163,16 +142,7 @@ public:
|
|||||||
* @return
|
* @return
|
||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) {
|
static ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_);
|
||||||
if (checkOrCreateClockMutex() != HasReturnvaluesIF::RETURN_OK) {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
MutexGuard helper(timeMutex);
|
|
||||||
|
|
||||||
leapSeconds = leapSeconds_;
|
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Leap Seconds since 1972
|
* Get the Leap Seconds since 1972
|
||||||
@ -184,17 +154,7 @@ public:
|
|||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - @c RETURN_FAILED on error
|
* - @c RETURN_FAILED on error
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t getLeapSeconds(uint16_t *leapSeconds_);
|
static ReturnValue_t Clock::getLeapSeconds(uint16_t *leapSeconds_);
|
||||||
ReturnValue_t Clock::getLeapSeconds(uint16_t *leapSeconds_) {
|
|
||||||
if (timeMutex == nullptr) {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
MutexGuard helper(timeMutex);
|
|
||||||
|
|
||||||
*leapSeconds_ = leapSeconds;
|
|
||||||
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/**
|
/**
|
||||||
@ -203,19 +163,7 @@ private:
|
|||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - Otherwise @c RETURN_FAILED if not able to create one
|
* - Otherwise @c RETURN_FAILED if not able to create one
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t Clock::checkOrCreateClockMutex() {
|
static ReturnValue_t Clock::checkOrCreateClockMutex();
|
||||||
if (timeMutex == nullptr) {
|
|
||||||
MutexFactory *mutexFactory = MutexFactory::instance();
|
|
||||||
if (mutexFactory == nullptr) {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
timeMutex = mutexFactory->createMutex();
|
|
||||||
if (timeMutex == nullptr) {
|
|
||||||
return HasReturnvaluesIF::RETURN_FAILED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
static MutexIF *timeMutex;
|
static MutexIF *timeMutex;
|
||||||
static uint16_t leapSeconds;
|
static uint16_t leapSeconds;
|
||||||
|
68
timemanager/ClockCommon.cpp
Normal file
68
timemanager/ClockCommon.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* ClockCommon.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jun 15, 2021
|
||||||
|
* Author: steffen
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Clock.h"
|
||||||
|
#include "../ipc/MutexGuard.h"
|
||||||
|
|
||||||
|
ReturnValue_t Clock::convertUTCToTT(timeval utc, timeval *tt) {
|
||||||
|
if (timeMutex == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t leapSeconds;
|
||||||
|
ReturnValue_t result = getLeapSeconds(&leapSeconds);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
timeval leapSeconds_timeval = { 0, 0 };
|
||||||
|
leapSeconds_timeval.tv_sec = leapSeconds;
|
||||||
|
|
||||||
|
//initial offset between UTC and TAI
|
||||||
|
timeval UTCtoTAI1972 = { 10, 0 };
|
||||||
|
|
||||||
|
timeval TAItoTT = { 32, 184000 };
|
||||||
|
|
||||||
|
*tt = utc + leapSeconds_timeval + UTCtoTAI1972 + TAItoTT;
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) {
|
||||||
|
if (checkOrCreateClockMutex() != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
MutexGuard helper(timeMutex);
|
||||||
|
|
||||||
|
leapSeconds = leapSeconds_;
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
ReturnValue_t Clock::getLeapSeconds(uint16_t *leapSeconds_) {
|
||||||
|
if (timeMutex == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
MutexGuard helper(timeMutex);
|
||||||
|
|
||||||
|
*leapSeconds_ = leapSeconds;
|
||||||
|
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ReturnValue_t Clock::checkOrCreateClockMutex() {
|
||||||
|
if (timeMutex == nullptr) {
|
||||||
|
MutexFactory *mutexFactory = MutexFactory::instance();
|
||||||
|
if (mutexFactory == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
timeMutex = mutexFactory->createMutex();
|
||||||
|
if (timeMutex == nullptr) {
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user