diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 86ab48c81e5496caa2fb05e7674831c28008b715..f25060c0a0ccdd77d361f71cffaeeb85e993991b 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -3,25 +3,6 @@ <option name="RIGHT_MARGIN" value="100" /> <option name="WRAP_WHEN_TYPING_REACHES_RIGHT_MARGIN" value="true" /> <Objective-C-extensions> - <file> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" /> - </file> - <class> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" /> - <option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" /> - </class> <extensions> <pair source="cpp" header="hpp" fileNamingConvention="PASCAL_CASE" /> <pair source="c" header="h" fileNamingConvention="NONE" /> diff --git a/inc/Helpers/TimeHelper.hpp b/inc/Helpers/TimeHelper.hpp index c03ca290e107552f1bbae58f87c50ec2559f9c4d..5939ad34ee2021d7a7447e0db9d65804971d8ebd 100644 --- a/inc/Helpers/TimeHelper.hpp +++ b/inc/Helpers/TimeHelper.hpp @@ -85,7 +85,7 @@ public: * @todo declare the implicit P-field * @todo check if we need milliseconds */ - static uint64_t implementCDSTimeFormat(struct TimeAndDate &TimeInfo); + static uint64_t implementCDStimeFormat(struct TimeAndDate &TimeInfo); /** * Parse the CDS time format(3.3 in CCSDS 301.0-B-4 standard) @@ -93,7 +93,7 @@ public: * @param seconds elapsed seconds since Unix epoch * @return the UTC date based on the /p */ - static struct TimeAndDate parseCDSTimeFormat(const uint8_t *data, uint8_t length); + static struct TimeAndDate parseCDStimeFormat(const uint8_t *data, uint8_t length); /** * Dummy function created only to access `mkUTCtime` for testing diff --git a/src/Helpers/TimeHelper.cpp b/src/Helpers/TimeHelper.cpp index 6baaf1d17ccc03d304aa4063e97892879988c71a..c7ed622eb28b795cfe0de9c696c082f2752abf10 100644 --- a/src/Helpers/TimeHelper.cpp +++ b/src/Helpers/TimeHelper.cpp @@ -11,8 +11,8 @@ bool TimeHelper::IsLeapYear(uint16_t year) { } uint32_t TimeHelper::mkUTCtime(struct TimeAndDate &TimeInfo) { - uint32_t secs = 0; - for (uint16_t y = 1970; y < TimeInfo.year; ++y) { + uint32_t secs = 1546300800; // elapsed seconds since 1/1/2019 00:00:00 (UTC date) + for (uint16_t y = 2019; y < TimeInfo.year; ++y) { // secs += (IsLeapYear(y) ? 366 : 365) * SecondsPerDay; } for (uint16_t m = 1; m < TimeInfo.month; ++m) { @@ -50,11 +50,6 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) { TimeInfo.month++; seconds -= (DaysOfMonth[i] * SecondsPerDay); i++; - if (i == 1 && (seconds >= (IsLeapYear(TimeInfo.year) ? 29 : 28) * SecondsPerDay)) { - TimeInfo.month++; - seconds -= (IsLeapYear(TimeInfo.year) ? 29 : 28) * SecondsPerDay; - i++; - } } // calculate days @@ -81,7 +76,7 @@ struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) { return TimeInfo; } -uint64_t TimeHelper::implementCDSTimeFormat(struct TimeAndDate &TimeInfo) { +uint64_t TimeHelper::implementCDStimeFormat(struct 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` @@ -116,7 +111,7 @@ uint64_t TimeHelper::implementCDSTimeFormat(struct TimeAndDate &TimeInfo) { return timeFormat; } -struct TimeAndDate TimeHelper::parseCDSTimeFormat(const uint8_t *data, uint8_t length) { +struct TimeAndDate TimeHelper::parseCDStimeFormat(const uint8_t *data, uint8_t length) { // check if we have the correct length of the packet data assertI(length != 48, ErrorHandler::InternalErrorType::UnknownInternalError); diff --git a/src/Services/TimeManagementService.cpp b/src/Services/TimeManagementService.cpp index d5c16f3eda26d65e97fa19feb6c053e9d9d5b136..cf4095087cb73c6faafbf5f11dae3ba9137ba4d8 100644 --- a/src/Services/TimeManagementService.cpp +++ b/src/Services/TimeManagementService.cpp @@ -5,7 +5,7 @@ void TimeManagementService::cdsTimeReport(struct TimeAndDate &TimeInfo) { Message timeReport = createTM(3); - uint64_t timeFormat = TimeHelper::implementCDSTimeFormat(TimeInfo); + uint64_t timeFormat = TimeHelper::implementCDStimeFormat(TimeInfo); timeReport.appendHalfword(static_cast<uint16_t >(timeFormat >> 32)); timeReport.appendWord(static_cast<uint32_t >(timeFormat)); @@ -16,7 +16,7 @@ void TimeManagementService::cdsTimeReport(struct TimeAndDate &TimeInfo) { struct TimeAndDate TimeManagementService::cdsTimeRequest(Message &message) { // TC{9,128] CDS time request - struct TimeAndDate timeInfo = TimeHelper::parseCDSTimeFormat(message.data, 48); + struct TimeAndDate timeInfo = TimeHelper::parseCDStimeFormat(message.data, 48); return timeInfo; } diff --git a/test/Helpers/TimeHelper.cpp b/test/Helpers/TimeHelper.cpp index 820322c11df7eada6db3eb03be2f50cfc3ff3ffd..46497032ac33cc05fac6aff5bb616b2bf25c8fe1 100644 --- a/test/Helpers/TimeHelper.cpp +++ b/test/Helpers/TimeHelper.cpp @@ -5,8 +5,8 @@ TEST_CASE("Time format implementation", "[CUC]") { SECTION("Convert UTC date to elapsed seconds since Unix epoch") { struct TimeAndDate TimeInfo = {0}; - // 10/04/1998 10:15:00 - TimeInfo.year = 1998; + // 10/04/2020 10:15:00 + TimeInfo.year = 2020; TimeInfo.month = 4; TimeInfo.day = 10; TimeInfo.hour = 10; @@ -19,7 +19,7 @@ TEST_CASE("Time format implementation", "[CUC]") { uint16_t elapsedDays = currTime / 86400; uint32_t msOfDay = currTime % 86400 * 1000; uint64_t timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); - CHECK(TimeHelper::implementCDSTimeFormat(TimeInfo) == timeFormat); + CHECK(TimeHelper::implementCDStimeFormat(TimeInfo) == timeFormat); // 1/1/2019 00:00:00 TimeInfo.year = 2019; @@ -34,15 +34,15 @@ TEST_CASE("Time format implementation", "[CUC]") { elapsedDays = currTime / 86400; msOfDay = currTime % 86400 * 1000; timeFormat = (static_cast<uint64_t>(elapsedDays) << 32 | msOfDay); - CHECK(TimeHelper::implementCDSTimeFormat(TimeInfo) == timeFormat); + CHECK(TimeHelper::implementCDStimeFormat(TimeInfo) == timeFormat); } SECTION("Convert elapsed seconds since Unix epoch to UTC date"){ - uint32_t seconds = 892203300; // elapsed seconds between 10/04/1998 10:15:00 and Unix epoch + uint32_t seconds = 1586513700; // elapsed seconds between 10/04/2020 10:15:00 and Unix epoch TimeHelper time; struct TimeAndDate TimeInfo = time.get_utcTime(seconds); - CHECK(TimeInfo.year == 1998); + CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 4); CHECK(TimeInfo.day == 10); CHECK(TimeInfo.hour == 10); diff --git a/test/Services/TimeManagementService.cpp b/test/Services/TimeManagementService.cpp index 5d82c59d73a692f5d97e70fa03db6060995fe018..612c4cdeaaa5171d2ea0f45cdb9f6d4aab9309fe 100644 --- a/test/Services/TimeManagementService.cpp +++ b/test/Services/TimeManagementService.cpp @@ -6,8 +6,8 @@ TEST_CASE("TM[9,3]", "[service][st09]") { TimeManagementService timeService; struct TimeAndDate TimeInfo = {0}; - // 10/04/1998 10:15:00 - TimeInfo.year = 1998; + // 10/04/2020 10:15:00 + TimeInfo.year = 2020; TimeInfo.month = 4; TimeInfo.day = 10; TimeInfo.hour = 10; @@ -34,7 +34,7 @@ TEST_CASE("TM[9,3]", "[service][st09]") { message.appendWord(static_cast<uint32_t >(timeFormat)); TimeInfo = timeService.cdsTimeRequest(message); - CHECK(TimeInfo.year == 1998); + CHECK(TimeInfo.year == 2020); CHECK(TimeInfo.month == 4); CHECK(TimeInfo.day == 10); CHECK(TimeInfo.hour == 10);