diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index 7e32f3bf41809894f05e5a4b75273b8d7a28b061..7cd1920d5343fa6b8186f3c377369462a1cc8a91 100644 --- a/inc/Helpers/TimeHelper.hpp +++ b/inc/Helpers/TimeHelper.hpp @@ -8,7 +8,14 @@ #define SECONDS_PER_MINUTE 60u #define SECONDS_PER_HOUR 3600u #define SECONDS_PER_DAY 86400u -#define LEAP_SECONDS 27 // @todo keep the leap seconds up to date + +/** + * @todo If we use CUC time format then we should keep leap seconds up to date. Leap seconds are added in undefined + * periods of time, so we should find a way to adjust to these changes either in runtime using GPS or sending a new + * compiled code (changing the defined leap seconds) from the ground segment + */ +#define LEAP_SECONDS 27 + /** * This class formats the spacecraft time and cooperates closely with the ST[09] time management. @@ -87,7 +94,7 @@ public: * @todo time security for critical time operations * @todo declare the implicit P-field */ - static uint64_t generateCDStimeFormat(struct TimeAndDate& TimeInfo); + static uint64_t generateCDSTimeFormat(struct TimeAndDate& TimeInfo); /** * Parse the CDS time format (3.3 in CCSDS 301.0-B-4 standard) @@ -117,7 +124,7 @@ public: * @todo time security for critical time operations * @todo declare the implicit P-field */ - static uint32_t generateCUCtimeFormat(struct TimeAndDate& TimeInfo); + static uint32_t generateCUCTimeFormat(struct TimeAndDate& TimeInfo); /** * Parse the CUC time format (3.3 in CCSDS 301.0-B-4 standard) @@ -126,7 +133,7 @@ public: * fixed size of 32 bits * @return the UTC date */ - static TimeAndDate parseCUCtimeFormat(const uint8_t* data); + static TimeAndDate parseCUCTimeFormat(const uint8_t* data); }; #endif // ECSS_SERVICES_TIMEHELPER_HPP diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index 5805d84cf0b7c5d4238565e60a2e0a0a94aba8f5..16b6e16229b6469d6e0c554385be6e0f0ec665e7 100644 --- a/src/Helpers/TimeHelper.cpp +++ b/src/Helpers/TimeHelper.cpp @@ -91,7 +91,7 @@ struct TimeAndDate TimeHelper::secondsToUTC(uint32_t seconds) { return TimeInfo; } -uint64_t TimeHelper::generateCDStimeFormat(TimeAndDate& TimeInfo) { +uint64_t TimeHelper::generateCDSTimeFormat(TimeAndDate& TimeInfo) { /** * Define the T-field. The total number of octets for the implementation of T-field is 6(2 for * the `DAY` and 4 for the `ms of day` @@ -126,11 +126,11 @@ TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t* data) { return secondsToUTC(seconds); } -uint32_t TimeHelper::generateCUCtimeFormat(struct TimeAndDate& TimeInfo) { +uint32_t TimeHelper::generateCUCTimeFormat(struct TimeAndDate& TimeInfo) { return (utcToSeconds(TimeInfo) + LEAP_SECONDS); } -TimeAndDate TimeHelper::parseCUCtimeFormat(const uint8_t* data) { +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])); seconds -= LEAP_SECONDS; diff --git a/src/Services/TimeManagementService.cpp b/src/Services/TimeManagementService.cpp index 6a0a967ff91b8d36d559e47701939adf8ea592cf..44f69760a30644b0172b0c042502808137dd8558 100644 --- a/src/Services/TimeManagementService.cpp +++ b/src/Services/TimeManagementService.cpp @@ -5,7 +5,7 @@ void TimeManagementService::cdsTimeReport(TimeAndDate& TimeInfo) { Message timeReport = createTM(3); - uint64_t timeFormat = TimeHelper::generateCDStimeFormat(TimeInfo); + uint64_t timeFormat = TimeHelper::generateCDSTimeFormat(TimeInfo); timeReport.appendHalfword(static_cast<uint16_t>(timeFormat >> 32)); timeReport.appendWord(static_cast<uint32_t>(timeFormat)); diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index fdc7fbcdc2a0acb4a97ecc7af4a01220b4d8abe8..00577f65203e1260d1d210e50df4b0f1c71ba4e2 100644 --- a/test/Helpers/TimeHelper.cpp +++ b/test/Helpers/TimeHelper.cpp @@ -81,7 +81,7 @@ TEST_CASE("Time format implementation for CDS", "[CDS]") { uint16_t elapsedDays = currTime / 86400; uint32_t msOfDay = currTime % 86400 * 1000; uint64_t timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); - CHECK(TimeHelper::generateCDStimeFormat(TimeInfo) == timeFormat); + CHECK(TimeHelper::generateCDSTimeFormat(TimeInfo) == timeFormat); // 1/1/2019 00:00:00 TimeInfo.year = 2019; @@ -96,7 +96,7 @@ TEST_CASE("Time format implementation for CDS", "[CDS]") { elapsedDays = currTime / 86400; msOfDay = currTime % 86400 * 1000; timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); - CHECK(TimeHelper::generateCDStimeFormat(TimeInfo) == timeFormat); + CHECK(TimeHelper::generateCDSTimeFormat(TimeInfo) == timeFormat); // 5/12/2020 00:00:00 TimeInfo.year = 2020; @@ -239,11 +239,11 @@ TEST_CASE("Time format implementation for CUC", "[CUC]") { uint32_t currTime = TimeHelper::utcToSeconds(TimeInfo); uint32_t timeFormat = currTime + LEAP_SECONDS; - CHECK(TimeHelper::generateCUCtimeFormat(TimeInfo) == timeFormat); + CHECK(TimeHelper::generateCUCTimeFormat(TimeInfo) == timeFormat); Message message = Message(9, 128, Message::TC, 3); message.appendWord(timeFormat); - CHECK((TimeHelper::parseCUCtimeFormat(message.data) == TimeInfo) == true); + CHECK((TimeHelper::parseCUCTimeFormat(message.data) == TimeInfo) == true); // 1/1/2019 00:00:00 TimeInfo.year = 2019; @@ -256,9 +256,9 @@ TEST_CASE("Time format implementation for CUC", "[CUC]") { currTime = TimeHelper::utcToSeconds(TimeInfo); timeFormat = currTime + LEAP_SECONDS; // TAI format - CHECK(TimeHelper::generateCUCtimeFormat(TimeInfo) == timeFormat); + CHECK(TimeHelper::generateCUCTimeFormat(TimeInfo) == timeFormat); message = Message(9, 128, Message::TC, 3); message.appendWord(timeFormat); - CHECK((TimeHelper::parseCUCtimeFormat(message.data) == TimeInfo) == true); + CHECK((TimeHelper::parseCUCTimeFormat(message.data) == TimeInfo) == true); }