clock corrected
This commit is contained in:
parent
ea289be29e
commit
ab9965cb81
@ -11,156 +11,156 @@
|
|||||||
|
|
||||||
class Clock {
|
class Clock {
|
||||||
public:
|
public:
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t year; //!< Year, A.D.
|
uint32_t year; //!< Year, A.D.
|
||||||
uint32_t month; //!< Month, 1 .. 12.
|
uint32_t month; //!< Month, 1 .. 12.
|
||||||
uint32_t day; //!< Day, 1 .. 31.
|
uint32_t day; //!< Day, 1 .. 31.
|
||||||
uint32_t hour; //!< Hour, 0 .. 23.
|
uint32_t hour; //!< Hour, 0 .. 23.
|
||||||
uint32_t minute; //!< Minute, 0 .. 59.
|
uint32_t minute; //!< Minute, 0 .. 59.
|
||||||
uint32_t second; //!< Second, 0 .. 59.
|
uint32_t second; //!< Second, 0 .. 59.
|
||||||
uint32_t usecond; //!< Microseconds, 0 .. 999999
|
uint32_t usecond; //!< Microseconds, 0 .. 999999
|
||||||
} TimeOfDay_t;
|
} TimeOfDay_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method returns the number of clock ticks per second.
|
* This method returns the number of clock ticks per second.
|
||||||
* In RTEMS, this is typically 1000.
|
* In RTEMS, this is typically 1000.
|
||||||
* @return The number of ticks.
|
* @return The number of ticks.
|
||||||
*
|
*
|
||||||
* @deprecated, we should not worry about ticks, but only time
|
* @deprecated, we should not worry about ticks, but only time
|
||||||
*/
|
*/
|
||||||
static uint32_t getTicksPerSecond(void);
|
static uint32_t getTicksPerSecond(void);
|
||||||
/**
|
/**
|
||||||
* This system call sets the system time.
|
* This system call sets the system time.
|
||||||
* To set the time, it uses a TimeOfDay_t struct.
|
* To set the time, it uses a TimeOfDay_t struct.
|
||||||
* @param time The struct with the time settings to set.
|
* @param time The struct with the time settings to set.
|
||||||
* @return -@c RETURN_OK on success. Otherwise, the OS failure code
|
* @return -@c RETURN_OK on success. Otherwise, the OS failure code
|
||||||
* is returned.
|
* is returned.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t setClock(const TimeOfDay_t* time);
|
static ReturnValue_t setClock(const TimeOfDay_t* time);
|
||||||
/**
|
/**
|
||||||
* This system call sets the system time.
|
* This system call sets the system time.
|
||||||
* To set the time, it uses a timeval struct.
|
* To set the time, it uses a timeval struct.
|
||||||
* @param time The struct with the time settings to set.
|
* @param time The struct with the time settings to set.
|
||||||
* @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 setClock(const timeval* time);
|
static ReturnValue_t setClock(const timeval* time);
|
||||||
/**
|
/**
|
||||||
* This system call returns the current system clock in timeval format.
|
* 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
|
* The timval format has the fields @c tv_sec with seconds and @c tv_usec with
|
||||||
* microseconds since an OS-defined epoch.
|
* microseconds since an OS-defined epoch.
|
||||||
* @param time A pointer to a timeval struct where the current time is stored.
|
* @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.
|
* @return @c RETURN_OK on success. Otherwise, the OS failure code is returned.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t getClock_timeval(timeval* time);
|
static ReturnValue_t getClock_timeval(timeval* time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the time since boot in a timeval struct
|
* Get the time since boot in a timeval struct
|
||||||
*
|
*
|
||||||
* @param[out] time A pointer to a timeval struct where the uptime is stored.
|
* @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.
|
* @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()
|
* @deprecated, I do not think this should be able to fail, use timeval getUptime()
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t getUptime(timeval* uptime);
|
static ReturnValue_t getUptime(timeval* uptime);
|
||||||
|
|
||||||
static timeval getUptime();
|
static timeval getUptime();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the time since boot in milliseconds
|
* Get the time since boot in milliseconds
|
||||||
*
|
*
|
||||||
* This value can overflow! Still, it can be used to calculate time intervalls
|
* 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
|
* between two calls up to 49 days by always using uint32_t in the calculation
|
||||||
*
|
*
|
||||||
* @param ms uptime in ms
|
* @param ms uptime in ms
|
||||||
* @return RETURN_OK on success. Otherwise, the OS failure code is returned.
|
* @return RETURN_OK on success. Otherwise, the OS failure code is returned.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t getUptime(uint32_t* uptimeMs);
|
static ReturnValue_t getUptime(uint32_t* uptimeMs);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @return
|
||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - Otherwise, the OS failure code is returned.
|
* - 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
|
* @return
|
||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - Otherwise, the OS failure code is returned.
|
* - Otherwise, the OS failure code is returned.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t getDateAndTime(TimeOfDay_t* time);
|
static ReturnValue_t getDateAndTime(TimeOfDay_t* time);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
* @return
|
||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - Otherwise, the OS failure code is returned.
|
* - 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
|
* Converts a time represented as seconds and subseconds since unix
|
||||||
* epoch to days since J2000
|
* 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates and adds the offset between UTC and TT
|
* Calculates and adds the offset between UTC and TT
|
||||||
*
|
*
|
||||||
* Depends on the leap seconds to be set correctly.
|
* Depends on the leap seconds to be set correctly.
|
||||||
*
|
*
|
||||||
* @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
|
* @return
|
||||||
* - @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 convertUTCToTT(timeval utc, timeval* tt);
|
static ReturnValue_t convertUTCToTT(timeval utc, timeval* tt);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the Leap Seconds since 1972
|
* Set the Leap Seconds since 1972
|
||||||
*
|
*
|
||||||
* @param leapSeconds_
|
* @param leapSeconds_
|
||||||
* @return
|
* @return
|
||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - Otherwise, the OS failure code is returned.
|
* - Otherwise, the OS failure code is returned.
|
||||||
*/
|
*/
|
||||||
static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_);
|
static ReturnValue_t setLeapSeconds(const uint16_t leapSeconds_);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the Leap Seconds since 1972
|
* Get the Leap Seconds since 1972
|
||||||
*
|
*
|
||||||
* Must be set before!
|
* Must be set before!
|
||||||
*
|
*
|
||||||
* @param[out] leapSeconds_
|
* @param[out] leapSeconds_
|
||||||
* @return
|
* @return
|
||||||
* - @c RETURN_OK on success.
|
* - @c RETURN_OK on success.
|
||||||
* - Otherwise, the OS failure code is returned.
|
* - 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
|
* @return
|
||||||
* - @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 checkOrCreateClockMutex();
|
static ReturnValue_t checkOrCreateClockMutex();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static MutexIF* timeMutex;
|
static MutexIF* timeMutex;
|
||||||
static uint16_t leapSeconds;
|
static uint16_t leapSeconds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user