Skip to content
Snippets Groups Projects
Commit a58307d6 authored by thodkatz's avatar thodkatz
Browse files

Added CUC time format

parent 28026622
No related branches found
No related tags found
No related merge requests found
......@@ -13,15 +13,22 @@
* This class formats the spacecraft time and cooperates closely with the ST[09] time management.
*
* The ECSS standard supports two time formats: the CUC and CSD that are described in CCSDS
* 301.0-B-4 standard. The chosen time format is CDS and it is UTC-based (UTC: Coordinated
* Universal Time). It consists of two main fields: the time code preamble field (P-field) and
* the time specification field (T-field). The P-Field is the metadata for the T-Field. The
* T-Field is consisted of two segments: 1) the `DAY` and the 2) `ms of day` segments.
* The P-field won't be included in the code, because as the ECSS standards claims, it can be
* just implicitly declared.
* 301.0-B-4 standard.
*
* @note
* Since this code is UTC-based, the leap second correction must be made. The leap seconds that
* The CDS is UTC-based (UTC: Coordinated Universal Time). It consists of two main fields: the
* time code preamble field (P-field) and the time specification field (T-field). The P-Field is the metadata for the
* T-Field. The T-Field is consisted of two segments: 1) the `DAY` and the 2) `ms of day` segments. The P-field won't
* be included in the code, because as the ECSS standards claims, it can be just implicitly declared.
*
* The CUC time format consists of two main fields: the time code preamble field (P-field) and the time specification
* field(T-field). The T-Field contains the value of the time unit and the designer decides what the time unit will
* be, so this is a subject for discussion. The recommended time unit from the standard is the second and it is
* probably the best solution for accuracy.
*
* @notes
* The defined epoch for both time formats is 1 January 1958 00:00:00
*
* Since CDS format is UTC-based, the leap second correction must be made. The leap seconds that
* have been occurred between timestamps should be considered if a critical time-difference is
* needed
*
......@@ -89,6 +96,33 @@ public:
* @return the UTC date
*/
static TimeAndDate parseCDStimeFormat(const uint8_t* data);
/**
* Generate the CUC time format (3.3 in CCSDS 301.0-B-4 standard).
*
* Converts a UTC date to CUC time format.
*
* @note
* The T-field is specified for the seconds passed from the defined epoch 1 January 1958. We use 4 octets(32
* bits) for the time unit(seconds) because 32 bits for the seconds are enough to count 136 years! But if we use 24
* bits for the seconds then it will count 0,5 years and this isn't enough. Remember we can use only integers
* numbers of octets for the time unit(second)
*
* @param TimeInfo is the data provided from RTC (UTC)
* @return TimeFormat the CUC time format. More specific, 32 bits are used for the T-field (seconds since 1/1/1958)
* @todo time security for critical time operations
* @todo declare the implicit P-field
*/
static uint32_t generateCUCtimeFormat(struct TimeAndDate& TimeInfo);
/**
* Parse the CUC time format (3.3 in CCSDS 301.0-B-4 standard)
*
* @param data time information provided from the ground segment. The length of the data is a
* fixed size of 32 bits
* @return the UTC date
*/
static TimeAndDate parseCUCtimeFormat(const uint8_t* data);
};
#endif // ECSS_SERVICES_TIMEHELPER_HPP
......@@ -125,3 +125,14 @@ TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t* data) {
return secondsToUTC(seconds);
}
uint32_t TimeHelper::generateCUCtimeFormat(struct TimeAndDate& TimeInfo) {
return utcToSeconds(TimeInfo);
}
TimeAndDate TimeHelper::parseCUCtimeFormat(const uint8_t* data) {
uint32_t seconds = ((static_cast<uint32_t>(data[0])) << 24) | ((static_cast<uint32_t>(data[1]))) << 16 |
((static_cast<uint32_t>(data[2]))) << 8 | (static_cast<uint32_t>(data[3]));
return secondsToUTC(seconds);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment