clock update, definitions file

This commit is contained in:
Robin Müller 2020-11-03 16:06:30 +01:00
parent dcf36d4cee
commit 81f5783d37
10 changed files with 92 additions and 73 deletions

View File

@ -207,7 +207,9 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
// prepare and send update snapshot. // prepare and send update snapshot.
CommandMessage notification; CommandMessage notification;
// todo: serialize into store with timestamp. // todo: serialize into store with timestamp.
HousekeepingPacketUpdate updatePacket()
// HousekeepingPacketUpdate updatePacket(timeStamp, timeStampSize,
// owner->getDataSetHandle(receiver.dataId.sid));
store_address_t storeId; store_address_t storeId;
HousekeepingMessage::setUpdateSnapshotSetCommand( HousekeepingMessage::setUpdateSnapshotSetCommand(
&notification, receiver.dataId.sid, storeId); &notification, receiver.dataId.sid, storeId);

View File

@ -28,7 +28,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
} }
ReturnValue_t Service9TimeManagement::setTime() { ReturnValue_t Service9TimeManagement::setTime() {
Clock::TimeOfDay_t timeToSet; TimeOfDay_t timeToSet;
TimePacket timePacket(currentPacket.getApplicationData(), TimePacket timePacket(currentPacket.getApplicationData(),
currentPacket.getApplicationDataSize()); currentPacket.getApplicationDataSize());
ReturnValue_t result = CCSDSTime::convertFromCcsds(&timeToSet, ReturnValue_t result = CCSDSTime::convertFromCcsds(&timeToSet,

View File

@ -93,7 +93,7 @@ bool ServiceInterfaceBuffer::isBuffered() const {
} }
std::string* ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) { std::string* ServiceInterfaceBuffer::getPreamble(size_t * preambleSize) {
Clock::TimeOfDay_t loggerTime; TimeOfDay_t loggerTime;
Clock::getDateAndTime(&loggerTime); Clock::getDateAndTime(&loggerTime);
size_t currentSize = 0; size_t currentSize = 0;
char* parsePosition = &preamble[0]; char* parsePosition = &preamble[0];

View File

@ -1,4 +1,4 @@
#include "../timemanager/CCSDSTime.h" #include "CCSDSTime.h"
#include <FSFWConfig.h> #include <FSFWConfig.h>
#include <cstdio> #include <cstdio>
#include <cinttypes> #include <cinttypes>
@ -12,7 +12,7 @@ CCSDSTime::~CCSDSTime() {
} }
ReturnValue_t CCSDSTime::convertToCcsds(Ccs_seconds* to, ReturnValue_t CCSDSTime::convertToCcsds(Ccs_seconds* to,
const Clock::TimeOfDay_t* from) { const TimeOfDay_t* from) {
ReturnValue_t result = checkTimeOfDay(from); ReturnValue_t result = checkTimeOfDay(from);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
@ -32,7 +32,7 @@ ReturnValue_t CCSDSTime::convertToCcsds(Ccs_seconds* to,
} }
ReturnValue_t CCSDSTime::convertToCcsds(Ccs_mseconds* to, ReturnValue_t CCSDSTime::convertToCcsds(Ccs_mseconds* to,
const Clock::TimeOfDay_t* from) { const TimeOfDay_t* from) {
ReturnValue_t result = checkTimeOfDay(from); ReturnValue_t result = checkTimeOfDay(from);
if (result != RETURN_OK) { if (result != RETURN_OK) {
return result; return result;
@ -53,7 +53,7 @@ ReturnValue_t CCSDSTime::convertToCcsds(Ccs_mseconds* to,
return RETURN_OK; return RETURN_OK;
} }
ReturnValue_t CCSDSTime::convertFromCcsds(Clock::TimeOfDay_t* to, const uint8_t* from, ReturnValue_t CCSDSTime::convertFromCcsds(TimeOfDay_t* to, const uint8_t* from,
uint32_t length) { uint32_t length) {
ReturnValue_t result; ReturnValue_t result;
if (length > 0xFF) { if (length > 0xFF) {
@ -81,12 +81,12 @@ ReturnValue_t CCSDSTime::convertFromCcsds(Clock::TimeOfDay_t* to, const uint8_t*
} }
} }
ReturnValue_t CCSDSTime::convertFromCUC(Clock::TimeOfDay_t* to, const uint8_t* from, ReturnValue_t CCSDSTime::convertFromCUC(TimeOfDay_t* to, const uint8_t* from,
uint8_t length) { uint8_t length) {
return UNSUPPORTED_TIME_FORMAT; return UNSUPPORTED_TIME_FORMAT;
} }
ReturnValue_t CCSDSTime::convertFromCDS(Clock::TimeOfDay_t* to, const uint8_t* from, ReturnValue_t CCSDSTime::convertFromCDS(TimeOfDay_t* to, const uint8_t* from,
uint8_t length) { uint8_t length) {
timeval time; timeval time;
ReturnValue_t result = convertFromCDS(&time, from, NULL, length); ReturnValue_t result = convertFromCDS(&time, from, NULL, length);
@ -96,7 +96,7 @@ ReturnValue_t CCSDSTime::convertFromCDS(Clock::TimeOfDay_t* to, const uint8_t* f
return convertTimevalToTimeOfDay(to, &time); return convertTimevalToTimeOfDay(to, &time);
} }
ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to, const uint8_t* from, ReturnValue_t CCSDSTime::convertFromCCS(TimeOfDay_t* to, const uint8_t* from,
uint32_t* foundLength, uint32_t maxLength) { uint32_t* foundLength, uint32_t maxLength) {
uint8_t subsecondsLength = *from & 0b111; uint8_t subsecondsLength = *from & 0b111;
uint32_t totalLength = subsecondsLength + 8; uint32_t totalLength = subsecondsLength + 8;
@ -152,7 +152,7 @@ ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to, const uint8_t* f
} }
ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* from, ReturnValue_t CCSDSTime::convertFromASCII(TimeOfDay_t* to, const uint8_t* from,
uint8_t length) { uint8_t length) {
if (length < 19) { if (length < 19) {
return RETURN_FAILED; return RETURN_FAILED;
@ -427,7 +427,7 @@ ReturnValue_t CCSDSTime::convertFromCUC(timeval* to, const uint8_t* from,
return result; return result;
} }
ReturnValue_t CCSDSTime::checkTimeOfDay(const Clock::TimeOfDay_t* time) { ReturnValue_t CCSDSTime::checkTimeOfDay(const TimeOfDay_t* time) {
if ((time->month > 12) || (time->month == 0)) { if ((time->month > 12) || (time->month == 0)) {
return INVALID_TIME_FORMAT; return INVALID_TIME_FORMAT;
} }
@ -482,7 +482,7 @@ ReturnValue_t CCSDSTime::checkTimeOfDay(const Clock::TimeOfDay_t* time) {
} }
ReturnValue_t CCSDSTime::convertTimevalToTimeOfDay(Clock::TimeOfDay_t* to, ReturnValue_t CCSDSTime::convertTimevalToTimeOfDay(TimeOfDay_t* to,
timeval* from) { timeval* from) {
//This is rather tricky. Implement only if needed. Also, if so, move to OSAL. //This is rather tricky. Implement only if needed. Also, if so, move to OSAL.
return UNSUPPORTED_TIME_FORMAT; return UNSUPPORTED_TIME_FORMAT;
@ -592,7 +592,7 @@ uint32_t CCSDSTime::subsecondsToMicroseconds(uint16_t subseconds) {
ReturnValue_t CCSDSTime::convertFromCCS(timeval* to, const uint8_t* from, ReturnValue_t CCSDSTime::convertFromCCS(timeval* to, const uint8_t* from,
uint32_t* foundLength, uint32_t maxLength) { uint32_t* foundLength, uint32_t maxLength) {
Clock::TimeOfDay_t tempTime; TimeOfDay_t tempTime;
ReturnValue_t result = convertFromCCS(&tempTime, from, foundLength, ReturnValue_t result = convertFromCCS(&tempTime, from, foundLength,
maxLength); maxLength);
if (result != RETURN_OK) { if (result != RETURN_OK) {

View File

@ -1,9 +1,10 @@
#ifndef CCSDSTIME_H_ #ifndef FSFW_TIMEMANAGER_CCSDSTIME_H_
#define CCSDSTIME_H_ #define FSFW_TIMEMANAGER_CCSDSTIME_H_
// COULDDO: have calls in Clock.h which return time quality and use timespec accordingly // COULDDO: have calls in Clock.h which return time quality and use timespec accordingly
#include "Clock.h" #include "Clock.h"
#include "clockDefinitions.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include <cstdint> #include <cstdint>
@ -111,7 +112,7 @@ public:
* - @c INVALID_TIMECODE if not OK * - @c INVALID_TIMECODE if not OK
*/ */
static ReturnValue_t convertToCcsds(Ccs_seconds *to, static ReturnValue_t convertToCcsds(Ccs_seconds *to,
Clock::TimeOfDay_t const *from); TimeOfDay_t const *from);
/** /**
* Converts to CDS format from timeval. * Converts to CDS format from timeval.
@ -136,7 +137,7 @@ public:
* - @c INVALID_TIMECODE if not OK * - @c INVALID_TIMECODE if not OK
*/ */
static ReturnValue_t convertToCcsds(Ccs_mseconds *to, static ReturnValue_t convertToCcsds(Ccs_mseconds *to,
Clock::TimeOfDay_t const *from); TimeOfDay_t const *from);
/** /**
* SHOULDDO: can this be modified to recognize padding? * SHOULDDO: can this be modified to recognize padding?
@ -154,7 +155,7 @@ public:
* - @c LENGTH_MISMATCH if the length does not match the P Field * - @c LENGTH_MISMATCH if the length does not match the P Field
* - @c INVALID_TIME_FORMAT if the format or a value is invalid * - @c INVALID_TIME_FORMAT if the format or a value is invalid
*/ */
static ReturnValue_t convertFromCcsds(Clock::TimeOfDay_t *to, uint8_t const *from, static ReturnValue_t convertFromCcsds(TimeOfDay_t *to, uint8_t const *from,
uint32_t length); uint32_t length);
/** /**
@ -167,7 +168,7 @@ public:
static ReturnValue_t convertFromCcsds(timeval *to, uint8_t const *from, static ReturnValue_t convertFromCcsds(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength); uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCUC(Clock::TimeOfDay_t *to, uint8_t const *from, static ReturnValue_t convertFromCUC(TimeOfDay_t *to, uint8_t const *from,
uint8_t length); uint8_t length);
static ReturnValue_t convertFromCUC(timeval *to, uint8_t const *from, static ReturnValue_t convertFromCUC(timeval *to, uint8_t const *from,
@ -182,16 +183,16 @@ public:
static ReturnValue_t convertFromCCS(timeval *to, uint8_t pField, static ReturnValue_t convertFromCCS(timeval *to, uint8_t pField,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength); uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCDS(Clock::TimeOfDay_t *to, uint8_t const *from, static ReturnValue_t convertFromCDS(TimeOfDay_t *to, uint8_t const *from,
uint8_t length); uint8_t length);
static ReturnValue_t convertFromCDS(timeval *to, uint8_t const *from, static ReturnValue_t convertFromCDS(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength); uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(Clock::TimeOfDay_t *to, uint8_t const *from, static ReturnValue_t convertFromCCS(TimeOfDay_t *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength); uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to, uint8_t const *from, static ReturnValue_t convertFromASCII(TimeOfDay_t *to, uint8_t const *from,
uint8_t length); uint8_t length);
static uint32_t subsecondsToMicroseconds(uint16_t subseconds); static uint32_t subsecondsToMicroseconds(uint16_t subseconds);
@ -209,7 +210,7 @@ private:
*/ */
static ReturnValue_t checkCcs(const uint8_t* time, uint8_t length); static ReturnValue_t checkCcs(const uint8_t* time, uint8_t length);
static ReturnValue_t checkTimeOfDay(const Clock::TimeOfDay_t *time); static ReturnValue_t checkTimeOfDay(const TimeOfDay_t *time);
static const uint32_t SECONDS_PER_DAY = 24 * 60 * 60; static const uint32_t SECONDS_PER_DAY = 24 * 60 * 60;
static const uint32_t SECONDS_PER_NON_LEAP_YEAR = SECONDS_PER_DAY * 365; static const uint32_t SECONDS_PER_NON_LEAP_YEAR = SECONDS_PER_DAY * 365;
@ -226,8 +227,8 @@ private:
uint8_t *month, uint8_t *day); uint8_t *month, uint8_t *day);
static bool isLeapYear(uint32_t year); static bool isLeapYear(uint32_t year);
static ReturnValue_t convertTimevalToTimeOfDay(Clock::TimeOfDay_t* to, static ReturnValue_t convertTimevalToTimeOfDay(TimeOfDay_t* to,
timeval* from); timeval* from);
}; };
#endif /* CCSDSTIME_H_ */ #endif /* FSFW_TIMEMANAGER_CCSDSTIME_H_ */

View File

@ -1,6 +1,7 @@
#ifndef FRAMEWORK_TIMEMANAGER_CLOCK_H_ #ifndef FSFW_TIMEMANAGER_CLOCK_H_
#define FRAMEWORK_TIMEMANAGER_CLOCK_H_ #define FSFW_TIMEMANAGER_CLOCK_H_
#include "clockDefinitions.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include "../ipc/MutexFactory.h" #include "../ipc/MutexFactory.h"
#include "../globalfunctions/timevalOperations.h" #include "../globalfunctions/timevalOperations.h"
@ -8,20 +9,11 @@
#include <cstdint> #include <cstdint>
#include <sys/time.h> #include <sys/time.h>
//! Don't use these for time points, type is not large enough for UNIX epoch. // TODO: Maybe a namespace would be better/more fitting for this?
using dur_millis_t = uint32_t; // After all, right now it is just a collection of static functions.
// The mutex and leap seconds can be put in an anonymous namespace.
class Clock { class Clock {
public: public:
typedef struct {
uint32_t year; //!< Year, A.D.
uint32_t month; //!< Month, 1 .. 12.
uint32_t day; //!< Day, 1 .. 31.
uint32_t hour; //!< Hour, 0 .. 23.
uint32_t minute; //!< Minute, 0 .. 59.
uint32_t second; //!< Second, 0 .. 59.
uint32_t usecond; //!< Microseconds, 0 .. 999999
} TimeOfDay_t;
/** /**
* This method returns the number of clock ticks per second. * This method returns the number of clock ticks per second.
@ -84,13 +76,17 @@ public:
* Returns the time in microseconds since an OS-defined epoch. * Returns the time in microseconds since an OS-defined epoch.
* The time is returned in a 64 bit unsigned integer. * The time is returned in a 64 bit unsigned integer.
* @param time A pointer to a 64 bit unisigned integer where the data is stored. * @param time A pointer to a 64 bit unisigned integer where the data is stored.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned. * @return
* - @c RETURN_OK on success.
* - Otherwise, the OS failure code is returned.
*/ */
static ReturnValue_t getClock_usecs(uint64_t* time); static ReturnValue_t getClock_usecs(uint64_t* time);
/** /**
* Returns the time in a TimeOfDay_t struct. * Returns the time in a TimeOfDay_t struct.
* @param time A pointer to a TimeOfDay_t struct. * @param time A pointer to a TimeOfDay_t struct.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned. * @return
* - @c RETURN_OK on success.
* - Otherwise, the OS failure code is returned.
*/ */
static ReturnValue_t getDateAndTime(TimeOfDay_t* time); static ReturnValue_t getDateAndTime(TimeOfDay_t* time);
@ -98,17 +94,20 @@ public:
* Converts a time of day struct to POSIX seconds. * Converts a time of day struct to POSIX seconds.
* @param time The time of day as input * @param time The time of day as input
* @param timeval The corresponding seconds since the epoch. * @param timeval The corresponding seconds since the epoch.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned. * @return
* - @c RETURN_OK on success.
* - Otherwise, the OS failure code is returned.
*/ */
static ReturnValue_t convertTimeOfDayToTimeval(const TimeOfDay_t* from, static ReturnValue_t convertTimeOfDayToTimeval(const TimeOfDay_t* from,
timeval* to); timeval* to);
/** /**
* Converts a time represented as seconds and subseconds since unix epoch to days since J2000 * Converts a time represented as seconds and subseconds since unix
* epoch to days since J2000
* *
* @param time seconds since unix epoch * @param time seconds since unix epoch
* @param[out] JD2000 days since J2000 * @param[out] JD2000 days since J2000
* @return \c RETURN_OK * @return @c RETURN_OK
*/ */
static ReturnValue_t convertTimevalToJD2000(timeval time, double* JD2000); static ReturnValue_t convertTimevalToJD2000(timeval time, double* JD2000);
@ -119,7 +118,9 @@ public:
* *
* @param utc timeval, corresponding to UTC time * @param utc timeval, corresponding to UTC time
* @param[out] tt timeval, corresponding to Terrestial Time * @param[out] tt timeval, corresponding to Terrestial Time
* @return \c RETURN_OK on success, \c RETURN_FAILED if leapSeconds are not set * @return
* - @c RETURN_OK on success
* - @c RETURN_FAILED if leapSeconds are not set
*/ */
static ReturnValue_t convertUTCToTT(timeval utc, timeval* tt); static ReturnValue_t convertUTCToTT(timeval utc, timeval* tt);
@ -127,7 +128,9 @@ public:
* Set the Leap Seconds since 1972 * Set the Leap Seconds since 1972
* *
* @param leapSeconds_ * @param leapSeconds_
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned. * @return
* - @c RETURN_OK on success.
* - Otherwise, the OS failure code is returned.
*/ */
static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_); static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_);
@ -137,13 +140,17 @@ public:
* Must be set before! * Must be set before!
* *
* @param[out] leapSeconds_ * @param[out] leapSeconds_
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned. * @return
* - @c RETURN_OK on success.
* - Otherwise, the OS failure code is returned.
*/ */
static ReturnValue_t getLeapSeconds(uint16_t *leapSeconds_); static ReturnValue_t getLeapSeconds(uint16_t *leapSeconds_);
/** /**
* Function to check and create the Mutex for the clock * Function to check and create the Mutex for the clock
* @return \c RETURN_OK on success. Otherwise \c RETURN_FAILED if not able to create one * @return
* - @c RETURN_OK on success.
* - Otherwise @c RETURN_FAILED if not able to create one
*/ */
static ReturnValue_t checkOrCreateClockMutex(); static ReturnValue_t checkOrCreateClockMutex();
@ -153,4 +160,4 @@ private:
}; };
#endif /* FRAMEWORK_TIMEMANAGER_CLOCK_H_ */ #endif /* FSFW_TIMEMANAGER_CLOCK_H_ */

View File

@ -1,12 +1,6 @@
/** #ifndef FSFW_TIMEMANAGER_RECEIVESTIMEINFOIF_H_
* @file ReceivesTimeInfoIF.h #define FSFW_TIMEMANAGER_RECEIVESTIMEINFOIF_H_
* @brief This file defines the ReceivesTimeInfoIF class.
* @date 26.02.2013
* @author baetz
*/
#ifndef RECEIVESTIMEINFOIF_H_
#define RECEIVESTIMEINFOIF_H_
#include "../ipc/MessageQueueSenderIF.h" #include "../ipc/MessageQueueSenderIF.h"
/** /**
@ -29,4 +23,4 @@ public:
}; };
#endif /* RECEIVESTIMEINFOIF_H_ */ #endif /* FSFW_TIMEMANAGER_RECEIVESTIMEINFOIF_H_ */

View File

@ -1,15 +1,8 @@
/** #ifndef FSFW_TIMEMANAGER_TIMEMESSAGE_H_
* @file TimeMessage.h #define FSFW_TIMEMANAGER_TIMEMESSAGE_H_
* @brief This file defines the TimeMessage class.
* @date 26.02.2013
* @author baetz
*/
#ifndef TIMEMESSAGE_H_
#define TIMEMESSAGE_H_
#include "Clock.h"
#include "../ipc/MessageQueueMessage.h" #include "../ipc/MessageQueueMessage.h"
#include "../timemanager/Clock.h"
#include <cstring> #include <cstring>
class TimeMessage : public MessageQueueMessage { class TimeMessage : public MessageQueueMessage {
@ -53,4 +46,4 @@ public:
uint32_t getCounterValue(); uint32_t getCounterValue();
}; };
#endif /* TIMEMESSAGE_H_ */ #endif /* FSFW_TIMEMANAGER_TIMEMESSAGE_H_ */

View File

@ -1,5 +1,5 @@
#ifndef FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_ #ifndef FSFW_TIMEMANAGER_TIMESTAMPERIF_H_
#define FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_ #define FSFW_TIMEMANAGER_TIMESTAMPERIF_H_
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
@ -25,4 +25,4 @@ public:
#endif /* FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_ */ #endif /* FSFW_TIMEMANAGER_TIMESTAMPERIF_H_ */

View File

@ -0,0 +1,22 @@
#ifndef FSFW_TIMEMANAGER_CLOCKDEFINITIONS_H_
#define FSFW_TIMEMANAGER_CLOCKDEFINITIONS_H_
#include <cstdint>
// It would be better to put this in a clock namespace, but then we
// have a nameclash with the class Clock (which propably also should be put
// in a namespace)
typedef struct {
uint32_t year; //!< Year, A.D.
uint32_t month; //!< Month, 1 .. 12.
uint32_t day; //!< Day, 1 .. 31.
uint32_t hour; //!< Hour, 0 .. 23.
uint32_t minute; //!< Minute, 0 .. 59.
uint32_t second; //!< Second, 0 .. 59.
uint32_t usecond; //!< Microseconds, 0 .. 999999
} TimeOfDay_t;
//! Don't use these for time points, type is not large enough for UNIX epoch.
using dur_millis_t = uint32_t;
#endif /* FSFW_TIMEMANAGER_CLOCKDEFINITIONS_H_ */