renormalized line endings

This commit is contained in:
2020-08-28 18:33:29 +02:00
parent 9abd796e6f
commit 1b9c8446b7
381 changed files with 38723 additions and 38723 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,233 +1,233 @@
#ifndef CCSDSTIME_H_
#define CCSDSTIME_H_
// COULDDO: have calls in Clock.h which return time quality and use timespec accordingly
#include "../timemanager/Clock.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include <stdint.h>
bool operator<(const timeval& lhs, const timeval& rhs);
bool operator<=(const timeval& lhs, const timeval& rhs);
bool operator==(const timeval& lhs, const timeval& rhs);
/**
* static helper class for CCSDS Time Code Formats
*
* as described in CCSDS 301.0-B-3
*
* Still work in progress
*/
class CCSDSTime: public HasReturnvaluesIF {
public:
/**
* The Time code identifications, bits 4-6 in the P-Field
*/
enum TimeCodeIdentification {
CCS = 0b101,
CUC_LEVEL1 = 0b001,
CUC_LEVEL2 = 0b010,
CDS = 0b100,
AGENCY_DEFINED = 0b110
};
static const uint8_t P_FIELD_CUC_6B_CCSDS = (CUC_LEVEL1 << 4) + (3 << 2)
+ 2;
static const uint8_t P_FIELD_CUC_6B_AGENCY = (CUC_LEVEL2 << 4) + (3 << 2)
+ 2;
static const uint8_t P_FIELD_CDS_SHORT = (CDS << 4);
/**
* Struct for CDS day-segmented format.
*/
struct CDS_short {
uint8_t pField;
uint8_t dayMSB;
uint8_t dayLSB;
uint8_t msDay_hh;
uint8_t msDay_h;
uint8_t msDay_l;
uint8_t msDay_ll;
};
/**
* Struct for the CCS fromat in day of month variation with max resolution
*/
struct Ccs_seconds {
uint8_t pField;
uint8_t yearMSB;
uint8_t yearLSB;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
};
/**
* Struct for the CCS fromat in day of month variation with 10E-4 seconds resolution
*/
struct Ccs_mseconds {
uint8_t pField;
uint8_t yearMSB;
uint8_t yearLSB;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t secondEminus2;
uint8_t secondEminus4;
};
struct OBT_FLP {
uint8_t pFiled;
uint8_t seconds_hh;
uint8_t seconds_h;
uint8_t seconds_l;
uint8_t seconds_ll;
uint8_t subsecondsMSB;
uint8_t subsecondsLSB;
};
struct TimevalLess {
bool operator()(const timeval& lhs, const timeval& rhs) const {
return (lhs < rhs);
}
};
static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_TIME_HELPER_CLASS;
static const ReturnValue_t UNSUPPORTED_TIME_FORMAT = MAKE_RETURN_CODE(0);
static const ReturnValue_t NOT_ENOUGH_INFORMATION_FOR_TARGET_FORMAT =
MAKE_RETURN_CODE(1);
static const ReturnValue_t LENGTH_MISMATCH = MAKE_RETURN_CODE(2);
static const ReturnValue_t INVALID_TIME_FORMAT = MAKE_RETURN_CODE(3);
static const ReturnValue_t INVALID_DAY_OF_YEAR = MAKE_RETURN_CODE(4);
static const ReturnValue_t TIME_DOES_NOT_FIT_FORMAT = MAKE_RETURN_CODE(5);
/**
* convert a TimeofDay struct to ccs with seconds resolution
*
* @param to pointer to a CCS struct
* @param from pointer to a TimeOfDay Struct
* @return
* - @c RETURN_OK if OK
* - @c INVALID_TIMECODE if not OK
*/
static ReturnValue_t convertToCcsds(Ccs_seconds *to,
Clock::TimeOfDay_t const *from);
/**
* Converts to CDS format from timeval.
* @param to pointer to the CDS struct to generate
* @param from pointer to a timeval struct which comprises a time of day since UNIX epoch.
* @return
* - @c RETURN_OK as it assumes a valid timeval.
*/
static ReturnValue_t convertToCcsds(CDS_short* to, timeval const *from);
static ReturnValue_t convertToCcsds(OBT_FLP* to, timeval const *from);
/**
* convert a TimeofDay struct to ccs with 10E-3 seconds resolution
*
* The 10E-4 seconds in the CCS Struct are 0 as the TimeOfDay only has ms resolution
*
* @param to pointer to a CCS struct
* @param from pointer to a TimeOfDay Struct
* @return
* - @c RETURN_OK if OK
* - @c INVALID_TIMECODE if not OK
*/
static ReturnValue_t convertToCcsds(Ccs_mseconds *to,
Clock::TimeOfDay_t const *from);
/**
* SHOULDDO: can this be modified to recognize padding?
* Tries to interpret a Level 1 CCSDS time code
*
* It assumes binary formats contain a valid P Field and recognizes the ASCII format
* by the lack of one.
*
* @param to an empty TimeOfDay struct
* @param from pointer to an CCSDS Time code
* @param length length of the Time code
* @return
* - @c RETURN_OK if successful
* - @c UNSUPPORTED_TIME_FORMAT if a (possibly valid) time code is not supported
* - @c LENGTH_MISMATCH if the length does not match the P Field
* - @c INVALID_TIME_FORMAT if the format or a value is invalid
*/
static ReturnValue_t convertFromCcsds(Clock::TimeOfDay_t *to, uint8_t const *from,
uint32_t length);
/**
* not implemented yet
*
* @param to
* @param from
* @return
*/
static ReturnValue_t convertFromCcsds(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCUC(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromCUC(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCUC(timeval *to, uint8_t pField,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(timeval *to, uint8_t pField,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCDS(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromCDS(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(Clock::TimeOfDay_t *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static uint32_t subsecondsToMicroseconds(uint16_t subseconds);
private:
CCSDSTime();
virtual ~CCSDSTime();
/**
* checks a ccs time stream for validity
*
* Stream may be longer than the actual timecode
*
* @param time pointer to an Ccs stream
* @param length length of stream
* @return
*/
static ReturnValue_t checkCcs(const uint8_t* time, uint8_t length);
static ReturnValue_t checkTimeOfDay(const Clock::TimeOfDay_t *time);
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 DAYS_CCSDS_TO_UNIX_EPOCH = 4383; //!< Time difference between CCSDS and POSIX epoch. This is exact, because leap-seconds where not introduced before 1972.
static const uint32_t SECONDS_CCSDS_TO_UNIX_EPOCH = DAYS_CCSDS_TO_UNIX_EPOCH
* SECONDS_PER_DAY;
/**
* @param dayofYear
* @param year
* @param month
* @param day
*/
static ReturnValue_t convertDaysOfYear(uint16_t dayofYear, uint16_t year,
uint8_t *month, uint8_t *day);
static bool isLeapYear(uint32_t year);
static ReturnValue_t convertTimevalToTimeOfDay(Clock::TimeOfDay_t* to,
timeval* from);
};
#endif /* CCSDSTIME_H_ */
#ifndef CCSDSTIME_H_
#define CCSDSTIME_H_
// COULDDO: have calls in Clock.h which return time quality and use timespec accordingly
#include "../timemanager/Clock.h"
#include "../returnvalues/HasReturnvaluesIF.h"
#include <stdint.h>
bool operator<(const timeval& lhs, const timeval& rhs);
bool operator<=(const timeval& lhs, const timeval& rhs);
bool operator==(const timeval& lhs, const timeval& rhs);
/**
* static helper class for CCSDS Time Code Formats
*
* as described in CCSDS 301.0-B-3
*
* Still work in progress
*/
class CCSDSTime: public HasReturnvaluesIF {
public:
/**
* The Time code identifications, bits 4-6 in the P-Field
*/
enum TimeCodeIdentification {
CCS = 0b101,
CUC_LEVEL1 = 0b001,
CUC_LEVEL2 = 0b010,
CDS = 0b100,
AGENCY_DEFINED = 0b110
};
static const uint8_t P_FIELD_CUC_6B_CCSDS = (CUC_LEVEL1 << 4) + (3 << 2)
+ 2;
static const uint8_t P_FIELD_CUC_6B_AGENCY = (CUC_LEVEL2 << 4) + (3 << 2)
+ 2;
static const uint8_t P_FIELD_CDS_SHORT = (CDS << 4);
/**
* Struct for CDS day-segmented format.
*/
struct CDS_short {
uint8_t pField;
uint8_t dayMSB;
uint8_t dayLSB;
uint8_t msDay_hh;
uint8_t msDay_h;
uint8_t msDay_l;
uint8_t msDay_ll;
};
/**
* Struct for the CCS fromat in day of month variation with max resolution
*/
struct Ccs_seconds {
uint8_t pField;
uint8_t yearMSB;
uint8_t yearLSB;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
};
/**
* Struct for the CCS fromat in day of month variation with 10E-4 seconds resolution
*/
struct Ccs_mseconds {
uint8_t pField;
uint8_t yearMSB;
uint8_t yearLSB;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
uint8_t secondEminus2;
uint8_t secondEminus4;
};
struct OBT_FLP {
uint8_t pFiled;
uint8_t seconds_hh;
uint8_t seconds_h;
uint8_t seconds_l;
uint8_t seconds_ll;
uint8_t subsecondsMSB;
uint8_t subsecondsLSB;
};
struct TimevalLess {
bool operator()(const timeval& lhs, const timeval& rhs) const {
return (lhs < rhs);
}
};
static const uint8_t INTERFACE_ID = CLASS_ID::CCSDS_TIME_HELPER_CLASS;
static const ReturnValue_t UNSUPPORTED_TIME_FORMAT = MAKE_RETURN_CODE(0);
static const ReturnValue_t NOT_ENOUGH_INFORMATION_FOR_TARGET_FORMAT =
MAKE_RETURN_CODE(1);
static const ReturnValue_t LENGTH_MISMATCH = MAKE_RETURN_CODE(2);
static const ReturnValue_t INVALID_TIME_FORMAT = MAKE_RETURN_CODE(3);
static const ReturnValue_t INVALID_DAY_OF_YEAR = MAKE_RETURN_CODE(4);
static const ReturnValue_t TIME_DOES_NOT_FIT_FORMAT = MAKE_RETURN_CODE(5);
/**
* convert a TimeofDay struct to ccs with seconds resolution
*
* @param to pointer to a CCS struct
* @param from pointer to a TimeOfDay Struct
* @return
* - @c RETURN_OK if OK
* - @c INVALID_TIMECODE if not OK
*/
static ReturnValue_t convertToCcsds(Ccs_seconds *to,
Clock::TimeOfDay_t const *from);
/**
* Converts to CDS format from timeval.
* @param to pointer to the CDS struct to generate
* @param from pointer to a timeval struct which comprises a time of day since UNIX epoch.
* @return
* - @c RETURN_OK as it assumes a valid timeval.
*/
static ReturnValue_t convertToCcsds(CDS_short* to, timeval const *from);
static ReturnValue_t convertToCcsds(OBT_FLP* to, timeval const *from);
/**
* convert a TimeofDay struct to ccs with 10E-3 seconds resolution
*
* The 10E-4 seconds in the CCS Struct are 0 as the TimeOfDay only has ms resolution
*
* @param to pointer to a CCS struct
* @param from pointer to a TimeOfDay Struct
* @return
* - @c RETURN_OK if OK
* - @c INVALID_TIMECODE if not OK
*/
static ReturnValue_t convertToCcsds(Ccs_mseconds *to,
Clock::TimeOfDay_t const *from);
/**
* SHOULDDO: can this be modified to recognize padding?
* Tries to interpret a Level 1 CCSDS time code
*
* It assumes binary formats contain a valid P Field and recognizes the ASCII format
* by the lack of one.
*
* @param to an empty TimeOfDay struct
* @param from pointer to an CCSDS Time code
* @param length length of the Time code
* @return
* - @c RETURN_OK if successful
* - @c UNSUPPORTED_TIME_FORMAT if a (possibly valid) time code is not supported
* - @c LENGTH_MISMATCH if the length does not match the P Field
* - @c INVALID_TIME_FORMAT if the format or a value is invalid
*/
static ReturnValue_t convertFromCcsds(Clock::TimeOfDay_t *to, uint8_t const *from,
uint32_t length);
/**
* not implemented yet
*
* @param to
* @param from
* @return
*/
static ReturnValue_t convertFromCcsds(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCUC(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromCUC(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCUC(timeval *to, uint8_t pField,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(timeval *to, uint8_t pField,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCDS(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromCDS(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(Clock::TimeOfDay_t *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static uint32_t subsecondsToMicroseconds(uint16_t subseconds);
private:
CCSDSTime();
virtual ~CCSDSTime();
/**
* checks a ccs time stream for validity
*
* Stream may be longer than the actual timecode
*
* @param time pointer to an Ccs stream
* @param length length of stream
* @return
*/
static ReturnValue_t checkCcs(const uint8_t* time, uint8_t length);
static ReturnValue_t checkTimeOfDay(const Clock::TimeOfDay_t *time);
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 DAYS_CCSDS_TO_UNIX_EPOCH = 4383; //!< Time difference between CCSDS and POSIX epoch. This is exact, because leap-seconds where not introduced before 1972.
static const uint32_t SECONDS_CCSDS_TO_UNIX_EPOCH = DAYS_CCSDS_TO_UNIX_EPOCH
* SECONDS_PER_DAY;
/**
* @param dayofYear
* @param year
* @param month
* @param day
*/
static ReturnValue_t convertDaysOfYear(uint16_t dayofYear, uint16_t year,
uint8_t *month, uint8_t *day);
static bool isLeapYear(uint32_t year);
static ReturnValue_t convertTimevalToTimeOfDay(Clock::TimeOfDay_t* to,
timeval* from);
};
#endif /* CCSDSTIME_H_ */

View File

@ -1,155 +1,155 @@
#ifndef FRAMEWORK_TIMEMANAGER_CLOCK_H_
#define FRAMEWORK_TIMEMANAGER_CLOCK_H_
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../ipc/MutexFactory.h"
#include "../globalfunctions/timevalOperations.h"
#include <cstdint>
#include <sys/time.h>
//! Don't use these for time points, type is not large enough for UNIX epoch.
using dur_millis_t = uint32_t;
using dur_seconds_t = double;
class Clock {
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.
* In RTEMS, this is typically 1000.
* @return The number of ticks.
*
* @deprecated, we should not worry about ticks, but only time
*/
static uint32_t getTicksPerSecond(void);
/**
* This system call sets the system time.
* To set the time, it uses a TimeOfDay_t struct.
* @param time The struct with the time settings to set.
* @return -@c RETURN_OK on success. Otherwise, the OS failure code
* is returned.
*/
static ReturnValue_t setClock(const TimeOfDay_t* time);
/**
* This system call sets the system time.
* To set the time, it uses a timeval struct.
* @param time The struct with the time settings to set.
* @return -@c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t setClock(const timeval* time);
/**
* This system call returns the current system clock in timeval format.
* The timval format has the fields @c tv_sec with seconds and @c tv_usec with
* microseconds since an OS-defined epoch.
* @param time A pointer to a timeval struct where the current time is stored.
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getClock_timeval(timeval* time);
/**
* Get the time since boot in a timeval struct
*
* @param[out] time A pointer to a timeval struct where the uptime is stored.
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
*
* @deprecated, I do not think this should be able to fail, use timeval getUptime()
*/
static ReturnValue_t getUptime(timeval* uptime);
static timeval getUptime();
/**
* Get the time since boot in milliseconds
*
* This value can overflow! Still, it can be used to calculate time intervalls
* between two calls up to 49 days by always using uint32_t in the calculation
*
* @param ms uptime in ms
* @return RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getUptime(uint32_t* uptimeMs);
/**
* Returns the time in microseconds since an OS-defined epoch.
* 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.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getClock_usecs(uint64_t* time);
/**
* Returns the time in 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.
*/
static ReturnValue_t getDateAndTime(TimeOfDay_t* time);
/**
* Converts a time of day struct to POSIX seconds.
* @param time The time of day as input
* @param timeval The corresponding seconds since the epoch.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t convertTimeOfDayToTimeval(const TimeOfDay_t* from,
timeval* to);
/**
* Converts a time represented as seconds and subseconds since unix epoch to days since J2000
*
* @param time seconds since unix epoch
* @param[out] JD2000 days since J2000
* @return \c RETURN_OK
*/
static ReturnValue_t convertTimevalToJD2000(timeval time, double* JD2000);
/**
* Calculates and adds the offset between UTC and TT
*
* Depends on the leap seconds to be set correctly.
*
* @param utc timeval, corresponding to UTC time
* @param[out] tt timeval, corresponding to Terrestial Time
* @return \c RETURN_OK on success, \c RETURN_FAILED if leapSeconds are not set
*/
static ReturnValue_t convertUTCToTT(timeval utc, timeval* tt);
/**
* Set the Leap Seconds since 1972
*
* @param leapSeconds_
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_);
/**
* Get the Leap Seconds since 1972
*
* Must be set before!
*
* @param[out] leapSeconds_
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getLeapSeconds(uint16_t *leapSeconds_);
/**
* 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
*/
static ReturnValue_t checkOrCreateClockMutex();
private:
static MutexIF* timeMutex;
static uint16_t leapSeconds;
};
#endif /* FRAMEWORK_TIMEMANAGER_CLOCK_H_ */
#ifndef FRAMEWORK_TIMEMANAGER_CLOCK_H_
#define FRAMEWORK_TIMEMANAGER_CLOCK_H_
#include "../returnvalues/HasReturnvaluesIF.h"
#include "../ipc/MutexFactory.h"
#include "../globalfunctions/timevalOperations.h"
#include <cstdint>
#include <sys/time.h>
//! Don't use these for time points, type is not large enough for UNIX epoch.
using dur_millis_t = uint32_t;
using dur_seconds_t = double;
class Clock {
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.
* In RTEMS, this is typically 1000.
* @return The number of ticks.
*
* @deprecated, we should not worry about ticks, but only time
*/
static uint32_t getTicksPerSecond(void);
/**
* This system call sets the system time.
* To set the time, it uses a TimeOfDay_t struct.
* @param time The struct with the time settings to set.
* @return -@c RETURN_OK on success. Otherwise, the OS failure code
* is returned.
*/
static ReturnValue_t setClock(const TimeOfDay_t* time);
/**
* This system call sets the system time.
* To set the time, it uses a timeval struct.
* @param time The struct with the time settings to set.
* @return -@c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t setClock(const timeval* time);
/**
* This system call returns the current system clock in timeval format.
* The timval format has the fields @c tv_sec with seconds and @c tv_usec with
* microseconds since an OS-defined epoch.
* @param time A pointer to a timeval struct where the current time is stored.
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getClock_timeval(timeval* time);
/**
* Get the time since boot in a timeval struct
*
* @param[out] time A pointer to a timeval struct where the uptime is stored.
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
*
* @deprecated, I do not think this should be able to fail, use timeval getUptime()
*/
static ReturnValue_t getUptime(timeval* uptime);
static timeval getUptime();
/**
* Get the time since boot in milliseconds
*
* This value can overflow! Still, it can be used to calculate time intervalls
* between two calls up to 49 days by always using uint32_t in the calculation
*
* @param ms uptime in ms
* @return RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getUptime(uint32_t* uptimeMs);
/**
* Returns the time in microseconds since an OS-defined epoch.
* 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.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getClock_usecs(uint64_t* time);
/**
* Returns the time in 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.
*/
static ReturnValue_t getDateAndTime(TimeOfDay_t* time);
/**
* Converts a time of day struct to POSIX seconds.
* @param time The time of day as input
* @param timeval The corresponding seconds since the epoch.
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t convertTimeOfDayToTimeval(const TimeOfDay_t* from,
timeval* to);
/**
* Converts a time represented as seconds and subseconds since unix epoch to days since J2000
*
* @param time seconds since unix epoch
* @param[out] JD2000 days since J2000
* @return \c RETURN_OK
*/
static ReturnValue_t convertTimevalToJD2000(timeval time, double* JD2000);
/**
* Calculates and adds the offset between UTC and TT
*
* Depends on the leap seconds to be set correctly.
*
* @param utc timeval, corresponding to UTC time
* @param[out] tt timeval, corresponding to Terrestial Time
* @return \c RETURN_OK on success, \c RETURN_FAILED if leapSeconds are not set
*/
static ReturnValue_t convertUTCToTT(timeval utc, timeval* tt);
/**
* Set the Leap Seconds since 1972
*
* @param leapSeconds_
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_);
/**
* Get the Leap Seconds since 1972
*
* Must be set before!
*
* @param[out] leapSeconds_
* @return \c RETURN_OK on success. Otherwise, the OS failure code is returned.
*/
static ReturnValue_t getLeapSeconds(uint16_t *leapSeconds_);
/**
* 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
*/
static ReturnValue_t checkOrCreateClockMutex();
private:
static MutexIF* timeMutex;
static uint16_t leapSeconds;
};
#endif /* FRAMEWORK_TIMEMANAGER_CLOCK_H_ */

View File

@ -1,45 +1,45 @@
/**
* @file Countdown.cpp
* @brief This file defines the Countdown class.
* @date 21.03.2013
* @author baetz
*/
#include "../timemanager/Countdown.h"
Countdown::Countdown(uint32_t initialTimeout) : startTime(0), timeout(initialTimeout) {
}
Countdown::~Countdown() {
}
ReturnValue_t Countdown::setTimeout(uint32_t miliseconds) {
ReturnValue_t return_value = Clock::getUptime( &startTime );
timeout = miliseconds;
return return_value;
}
bool Countdown::hasTimedOut() const {
uint32_t current_time;
Clock::getUptime( &current_time );
if ( uint32_t(current_time - startTime) >= timeout) {
return true;
} else {
return false;
}
}
bool Countdown::isBusy() const {
return !hasTimedOut();
}
ReturnValue_t Countdown::resetTimer() {
return setTimeout(timeout);
}
void Countdown::timeOut() {
uint32_t current_time;
Clock::getUptime( &current_time );
startTime= current_time - timeout;
}
/**
* @file Countdown.cpp
* @brief This file defines the Countdown class.
* @date 21.03.2013
* @author baetz
*/
#include "../timemanager/Countdown.h"
Countdown::Countdown(uint32_t initialTimeout) : startTime(0), timeout(initialTimeout) {
}
Countdown::~Countdown() {
}
ReturnValue_t Countdown::setTimeout(uint32_t miliseconds) {
ReturnValue_t return_value = Clock::getUptime( &startTime );
timeout = miliseconds;
return return_value;
}
bool Countdown::hasTimedOut() const {
uint32_t current_time;
Clock::getUptime( &current_time );
if ( uint32_t(current_time - startTime) >= timeout) {
return true;
} else {
return false;
}
}
bool Countdown::isBusy() const {
return !hasTimedOut();
}
ReturnValue_t Countdown::resetTimer() {
return setTimeout(timeout);
}
void Countdown::timeOut() {
uint32_t current_time;
Clock::getUptime( &current_time );
startTime= current_time - timeout;
}

View File

@ -1,31 +1,31 @@
/**
* @file Countdown.h
* @brief This file defines the Countdown class.
* @date 21.03.2013
* @author baetz
*/
#ifndef COUNTDOWN_H_
#define COUNTDOWN_H_
#include "../timemanager/Clock.h"
class Countdown {
private:
uint32_t startTime;
public:
uint32_t timeout;
Countdown(uint32_t initialTimeout = 0);
~Countdown();
ReturnValue_t setTimeout(uint32_t miliseconds);
bool hasTimedOut() const;
bool isBusy() const;
ReturnValue_t resetTimer(); //!< Use last set timeout value and restart timer.
void timeOut(); //!< Make hasTimedOut() return true
};
#endif /* COUNTDOWN_H_ */
/**
* @file Countdown.h
* @brief This file defines the Countdown class.
* @date 21.03.2013
* @author baetz
*/
#ifndef COUNTDOWN_H_
#define COUNTDOWN_H_
#include "../timemanager/Clock.h"
class Countdown {
private:
uint32_t startTime;
public:
uint32_t timeout;
Countdown(uint32_t initialTimeout = 0);
~Countdown();
ReturnValue_t setTimeout(uint32_t miliseconds);
bool hasTimedOut() const;
bool isBusy() const;
ReturnValue_t resetTimer(); //!< Use last set timeout value and restart timer.
void timeOut(); //!< Make hasTimedOut() return true
};
#endif /* COUNTDOWN_H_ */

View File

@ -1,32 +1,32 @@
/**
* @file 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"
/**
* This is a Interface for classes that receive timing information
* with the help of a dedicated message queue.
*/
class ReceivesTimeInfoIF {
public:
/**
* Returns the id of the queue which receives the timing information.
* @return Queue id of the timing queue.
*/
virtual MessageQueueId_t getTimeReceptionQueue() const = 0;
/**
* Empty virtual destructor.
*/
virtual ~ReceivesTimeInfoIF() {
}
};
#endif /* RECEIVESTIMEINFOIF_H_ */
/**
* @file 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"
/**
* This is a Interface for classes that receive timing information
* with the help of a dedicated message queue.
*/
class ReceivesTimeInfoIF {
public:
/**
* Returns the id of the queue which receives the timing information.
* @return Queue id of the timing queue.
*/
virtual MessageQueueId_t getTimeReceptionQueue() const = 0;
/**
* Empty virtual destructor.
*/
virtual ~ReceivesTimeInfoIF() {
}
};
#endif /* RECEIVESTIMEINFOIF_H_ */

View File

@ -1,57 +1,57 @@
#include "../timemanager/Stopwatch.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <iomanip>
Stopwatch::Stopwatch(bool displayOnDestruction,
StopwatchDisplayMode displayMode): displayOnDestruction(
displayOnDestruction), displayMode(displayMode) {
// Measures start time on initialization.
Clock::getClock_timeval(&startTime);
}
void Stopwatch::start() {
Clock::getClock_timeval(&startTime);
}
dur_millis_t Stopwatch::stop() {
stopInternal();
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
}
dur_seconds_t Stopwatch::stopSeconds() {
stopInternal();
return timevalOperations::toDouble(elapsedTime);
}
void Stopwatch::display() {
if(displayMode == StopwatchDisplayMode::MILLIS) {
sif::info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 +
elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl;
}
else if(displayMode == StopwatchDisplayMode::SECONDS) {
sif::info <<"Stopwatch: Operation took " << std::setprecision(3)
<< std::fixed << timevalOperations::toDouble(elapsedTime)
<< " seconds" << std::endl;
}
}
Stopwatch::~Stopwatch() {
if(displayOnDestruction) {
stopInternal();
display();
}
}
void Stopwatch::setDisplayMode(StopwatchDisplayMode displayMode) {
this->displayMode = displayMode;
}
StopwatchDisplayMode Stopwatch::getDisplayMode() const {
return displayMode;
}
void Stopwatch::stopInternal() {
timeval endTime;
Clock::getClock_timeval(&endTime);
elapsedTime = endTime - startTime;
}
#include "../timemanager/Stopwatch.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <iomanip>
Stopwatch::Stopwatch(bool displayOnDestruction,
StopwatchDisplayMode displayMode): displayOnDestruction(
displayOnDestruction), displayMode(displayMode) {
// Measures start time on initialization.
Clock::getClock_timeval(&startTime);
}
void Stopwatch::start() {
Clock::getClock_timeval(&startTime);
}
dur_millis_t Stopwatch::stop() {
stopInternal();
return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000;
}
dur_seconds_t Stopwatch::stopSeconds() {
stopInternal();
return timevalOperations::toDouble(elapsedTime);
}
void Stopwatch::display() {
if(displayMode == StopwatchDisplayMode::MILLIS) {
sif::info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 +
elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl;
}
else if(displayMode == StopwatchDisplayMode::SECONDS) {
sif::info <<"Stopwatch: Operation took " << std::setprecision(3)
<< std::fixed << timevalOperations::toDouble(elapsedTime)
<< " seconds" << std::endl;
}
}
Stopwatch::~Stopwatch() {
if(displayOnDestruction) {
stopInternal();
display();
}
}
void Stopwatch::setDisplayMode(StopwatchDisplayMode displayMode) {
this->displayMode = displayMode;
}
StopwatchDisplayMode Stopwatch::getDisplayMode() const {
return displayMode;
}
void Stopwatch::stopInternal() {
timeval endTime;
Clock::getClock_timeval(&endTime);
elapsedTime = endTime - startTime;
}

View File

@ -1,71 +1,71 @@
#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#include "../timemanager/Clock.h"
enum class StopwatchDisplayMode {
MILLIS,
SECONDS
};
/**
* @brief Simple Stopwatch implementation to measure elapsed time
* @details
* This class can be used to measure elapsed times. It also displays elapsed
* times automatically on destruction if not explicitely deactivated in the
* constructor. The default time format is the elapsed time in miliseconds
* in seconds as a double.
* @author R. Mueller
*/
class Stopwatch {
public:
/**
* Default constructor. Call "Stopwatch stopwatch" without brackets if
* no parameters are required!
* @param displayOnDestruction If set to true, displays measured time on
* object destruction
* @param displayMode Display format is either MS rounded or MS as double
* format
* @param outputPrecision If using double format, specify precision here.
*/
Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode
= StopwatchDisplayMode::MILLIS);
virtual~ Stopwatch();
/**
* Caches the start time
*/
void start();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in milliseconds (rounded)
*/
dur_millis_t stop();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in seconds (double precision)
*/
dur_seconds_t stopSeconds();
/**
* Displays the elapsed times on the osstream, depending on internal display
* mode.
*/
void display();
StopwatchDisplayMode getDisplayMode() const;
void setDisplayMode(StopwatchDisplayMode displayMode);
bool displayOnDestruction = true;
private:
timeval startTime {0, 0};
timeval elapsedTime {0, 0};
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS;
void stopInternal();
};
#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */
#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_
#include "../timemanager/Clock.h"
enum class StopwatchDisplayMode {
MILLIS,
SECONDS
};
/**
* @brief Simple Stopwatch implementation to measure elapsed time
* @details
* This class can be used to measure elapsed times. It also displays elapsed
* times automatically on destruction if not explicitely deactivated in the
* constructor. The default time format is the elapsed time in miliseconds
* in seconds as a double.
* @author R. Mueller
*/
class Stopwatch {
public:
/**
* Default constructor. Call "Stopwatch stopwatch" without brackets if
* no parameters are required!
* @param displayOnDestruction If set to true, displays measured time on
* object destruction
* @param displayMode Display format is either MS rounded or MS as double
* format
* @param outputPrecision If using double format, specify precision here.
*/
Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode
= StopwatchDisplayMode::MILLIS);
virtual~ Stopwatch();
/**
* Caches the start time
*/
void start();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in milliseconds (rounded)
*/
dur_millis_t stop();
/**
* Calculates the elapsed time since start and returns it
* @return elapsed time in seconds (double precision)
*/
dur_seconds_t stopSeconds();
/**
* Displays the elapsed times on the osstream, depending on internal display
* mode.
*/
void display();
StopwatchDisplayMode getDisplayMode() const;
void setDisplayMode(StopwatchDisplayMode displayMode);
bool displayOnDestruction = true;
private:
timeval startTime {0, 0};
timeval elapsedTime {0, 0};
StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS;
void stopInternal();
};
#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */

View File

@ -1,37 +1,37 @@
/**
* @file TimeMessage.cpp
* @brief This file defines the TimeMessage class.
* @date 26.02.2013
* @author baetz
*/
#include "../timemanager/TimeMessage.h"
TimeMessage::TimeMessage() {
this->messageSize += sizeof(timeval) + sizeof(uint32_t);
}
TimeMessage::TimeMessage(timeval setTime, uint32_t CounterValue) {
memcpy (this->getData(), &setTime, sizeof(timeval));
this->messageSize += sizeof(timeval) + sizeof(uint32_t);
memcpy (this->getData() + sizeof(timeval), &CounterValue, sizeof(uint32_t));
}
TimeMessage::~TimeMessage() {
}
timeval TimeMessage::getTime() {
timeval temp;
memcpy( &temp, this->getData(), sizeof(timeval));
return temp;
}
uint32_t TimeMessage::getCounterValue() {
uint32_t temp;
memcpy ( &temp, this->getData() + sizeof(timeval), sizeof(uint32_t));
return temp;
}
size_t TimeMessage::getMinimumMessageSize() {
return this->MAX_SIZE;
}
/**
* @file TimeMessage.cpp
* @brief This file defines the TimeMessage class.
* @date 26.02.2013
* @author baetz
*/
#include "../timemanager/TimeMessage.h"
TimeMessage::TimeMessage() {
this->messageSize += sizeof(timeval) + sizeof(uint32_t);
}
TimeMessage::TimeMessage(timeval setTime, uint32_t CounterValue) {
memcpy (this->getData(), &setTime, sizeof(timeval));
this->messageSize += sizeof(timeval) + sizeof(uint32_t);
memcpy (this->getData() + sizeof(timeval), &CounterValue, sizeof(uint32_t));
}
TimeMessage::~TimeMessage() {
}
timeval TimeMessage::getTime() {
timeval temp;
memcpy( &temp, this->getData(), sizeof(timeval));
return temp;
}
uint32_t TimeMessage::getCounterValue() {
uint32_t temp;
memcpy ( &temp, this->getData() + sizeof(timeval), sizeof(uint32_t));
return temp;
}
size_t TimeMessage::getMinimumMessageSize() {
return this->MAX_SIZE;
}

View File

@ -1,56 +1,56 @@
/**
* @file TimeMessage.h
* @brief This file defines the TimeMessage class.
* @date 26.02.2013
* @author baetz
*/
#ifndef TIMEMESSAGE_H_
#define TIMEMESSAGE_H_
#include "../ipc/MessageQueueMessage.h"
#include "../timemanager/Clock.h"
#include <cstring>
class TimeMessage : public MessageQueueMessage {
protected:
/**
* @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + \c sizeof(timeval) + sizeof(uint32_t).
*/
size_t getMinimumMessageSize();
public:
/**
* @ brief the size of a TimeMessage
*/
static const uint32_t MAX_SIZE = HEADER_SIZE + sizeof(timeval) + sizeof(uint32_t);
/**
* @brief In the default constructor, only the message_size is set.
*/
TimeMessage();
/**
* @brief With this constructor, the passed time information is directly put
* into the message.
* @param setTime The time information to put into the message.
* @param counterValue The counterValue to put into the message (GPS PPS).
*/
TimeMessage( timeval setTime, uint32_t counterValue = 0 );
/**
* @brief The class's destructor is empty.
*/
~TimeMessage();
/**
* @brief This getter returns the time information in timeval format.
* @return Returns the time stored in this packet.
*/
timeval getTime();
/**
* @brief This getter returns the CounterValue in uint32_t format.
* @return Returns the CounterValue stored in this packet.
*/
uint32_t getCounterValue();
};
#endif /* TIMEMESSAGE_H_ */
/**
* @file TimeMessage.h
* @brief This file defines the TimeMessage class.
* @date 26.02.2013
* @author baetz
*/
#ifndef TIMEMESSAGE_H_
#define TIMEMESSAGE_H_
#include "../ipc/MessageQueueMessage.h"
#include "../timemanager/Clock.h"
#include <cstring>
class TimeMessage : public MessageQueueMessage {
protected:
/**
* @brief This call always returns the same fixed size of the message.
* @return Returns HEADER_SIZE + \c sizeof(timeval) + sizeof(uint32_t).
*/
size_t getMinimumMessageSize();
public:
/**
* @ brief the size of a TimeMessage
*/
static const uint32_t MAX_SIZE = HEADER_SIZE + sizeof(timeval) + sizeof(uint32_t);
/**
* @brief In the default constructor, only the message_size is set.
*/
TimeMessage();
/**
* @brief With this constructor, the passed time information is directly put
* into the message.
* @param setTime The time information to put into the message.
* @param counterValue The counterValue to put into the message (GPS PPS).
*/
TimeMessage( timeval setTime, uint32_t counterValue = 0 );
/**
* @brief The class's destructor is empty.
*/
~TimeMessage();
/**
* @brief This getter returns the time information in timeval format.
* @return Returns the time stored in this packet.
*/
timeval getTime();
/**
* @brief This getter returns the CounterValue in uint32_t format.
* @return Returns the CounterValue stored in this packet.
*/
uint32_t getCounterValue();
};
#endif /* TIMEMESSAGE_H_ */

View File

@ -1,24 +1,24 @@
#ifndef FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_
#define FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_
#include "../returnvalues/HasReturnvaluesIF.h"
/**
* A class implementing this IF provides facilities to add a time stamp to the
* buffer provided.
* Implementors need to ensure that calling the method is thread-safe, i.e.
* addTimeStamp may be called in parallel from a different context.
*/
class TimeStamperIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF;
static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1);
static const uint8_t MISSION_TIMESTAMP_SIZE = 8; //!< This is a mission-specific constant and determines the total size reserved for timestamps.
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize) = 0;
virtual ~TimeStamperIF() {}
};
#endif /* FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_ */
#ifndef FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_
#define FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_
#include "../returnvalues/HasReturnvaluesIF.h"
/**
* A class implementing this IF provides facilities to add a time stamp to the
* buffer provided.
* Implementors need to ensure that calling the method is thread-safe, i.e.
* addTimeStamp may be called in parallel from a different context.
*/
class TimeStamperIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF;
static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1);
static const uint8_t MISSION_TIMESTAMP_SIZE = 8; //!< This is a mission-specific constant and determines the total size reserved for timestamps.
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize) = 0;
virtual ~TimeStamperIF() {}
};
#endif /* FRAMEWORK_TIMEMANAGER_TIMESTAMPERIF_H_ */