From 7225040a05a45acbba55d1ab810220e12efde572 Mon Sep 17 00:00:00 2001 From: thodkatz <thodkatz@gmail.com> Date: Fri, 3 May 2019 17:25:04 +0300 Subject: [PATCH] Implement code review suggestions --- inc/Helpers/TimeHelper.hpp | 15 +++++++++++---- src/Helpers/TimeHelper.cpp | 6 +++--- src/Services/TimeManagementService.cpp | 2 +- test/Helpers/TimeHelper.cpp | 12 ++++++------ 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index 7e32f3bf..7cd1920d 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 5805d84c..16b6e162 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 6a0a967f..44f69760 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 fdc7fbcd..00577f65 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); } -- GitLab