diff --git a/inc/ECSS_Definitions.hpp b/inc/ECSS_Definitions.hpp index 0e49823c31d394295f1cfa507d873ed1997a1611..fd05e87b09642dcbf7efed9ac4256fd22c8c493e 100644 --- a/inc/ECSS_Definitions.hpp +++ b/inc/ECSS_Definitions.hpp @@ -2,6 +2,7 @@ #define ECSS_SERVICES_ECSS_DEFINITIONS_H #include <cstdint> +#include <chrono> /** * @defgroup ECSSDefinitions ECSS Defined Constants * @@ -107,7 +108,7 @@ inline const uint8_t ECSSMaxNumberOfTimeSchedActivities = 10; * have in order * @see TimeBasedSchedulingService */ -inline const uint8_t ECSSTimeMarginForActivation = 60; +inline constexpr std::chrono::duration<uint8_t> ECSSTimeMarginForActivation(60); /** * @brief Maximum size of an event's auxiliary data diff --git a/inc/Helpers/Statistic.hpp b/inc/Helpers/Statistic.hpp index bd451b44bf1f566c1c0a0ae59e716880922ae9d2..63fa8d644f8bcb9cd27ebc531444c04c636c9bd6 100644 --- a/inc/Helpers/Statistic.hpp +++ b/inc/Helpers/Statistic.hpp @@ -15,8 +15,8 @@ class Statistic { public: uint16_t selfSamplingInterval = 0; uint16_t sampleCounter = 0; - Time::CustomCUC_t timeOfMaxValue; - Time::CustomCUC_t timeOfMinValue; + Time::DefaultCUC timeOfMaxValue; + Time::DefaultCUC timeOfMinValue; double max = -std::numeric_limits<double>::infinity(); double min = std::numeric_limits<double>::infinity(); double sumOfSquares = 0; diff --git a/inc/Helpers/TimeGetter.hpp b/inc/Helpers/TimeGetter.hpp index d2dfaf7e7fc45787e695e0b0ba1a1e4a5073daba..4417d6735d040c4be9e40dec10b9043552231cd9 100644 --- a/inc/Helpers/TimeGetter.hpp +++ b/inc/Helpers/TimeGetter.hpp @@ -23,12 +23,12 @@ public: * Converts the current UTC time, to a CUC formatted timestamp. * @note * The original format of the CUC (etl array of bits), is not used here, because it's easier to append - * a type uint64_t to a message object, rather than a whole array. Thus, we use the custom CUC format. + * a type uint32_t to a message object, rather than a whole array. Thus, we use the custom CUC format. * - * @return CUC timestamp, formatted as elapsed 100ms ticks. - * @see Time.hpp + * @return CUC timestamp, formatted as elapsed ticks. + * @see Time */ - static Time::CustomCUC_t getCurrentTimeCustomCUC(); + static Time::DefaultCUC getCurrentTimeDefaultCUC(); }; #endif // ECSS_SERVICES_TIMEGETTER_HPP diff --git a/inc/Message.hpp b/inc/Message.hpp index 360867b90b18cc9cc6fbca5d1ca78f33a8d95007..dfb142f7ab90fc1d7e18efd83f1edd8f399378ec 100644 --- a/inc/Message.hpp +++ b/inc/Message.hpp @@ -1,6 +1,7 @@ #ifndef ECSS_SERVICES_PACKET_H #define ECSS_SERVICES_PACKET_H +#include <Time/TimeStamp.hpp> #include <cstdint> #include <etl/String.hpp> #include <etl/wstring.h> @@ -148,10 +149,21 @@ public: void appendWord(uint32_t value); /** - * Appends a type CustomCUC (CUC formatted timestamp) to the message. + * Appends any CUC timestamp to the message, including the header. */ - void appendCustomCUCTimeStamp(const Time::CustomCUC_t& timeCUC) { - appendUint64(timeCUC.elapsed100msTicks); + template <class Ts> + void appendCUCTimeStamp(const Ts& timestamp) { + etl::array<uint8_t, Time::CUCTimestampMaximumSize> text = timestamp.formatAsCUC(); + + appendString(String<Time::CUCTimestampMaximumSize>(text.data(), text.size())); + } + + /** + * Appends a default timestamp object to the message, without the header + */ + void appendDefaultCUCTimeStamp(Time::DefaultCUC timestamp) { + static_assert(std::is_same_v<uint32_t, decltype(timestamp.formatAsBytes())>, "The default timestamp should be 4 bytes"); + appendUint32(timestamp.formatAsBytes()); } /** @@ -563,7 +575,7 @@ public: return reinterpret_cast<float&>(value); } - float readDouble() { + double readDouble() { static_assert(sizeof(uint64_t) == sizeof(double), "Double numbers must be 64 bits long"); uint64_t value = readUint64(); @@ -571,13 +583,13 @@ public: } /** - * Fetches a timestamp in a custom CUC format consisting of 8 bytes from the current position in the message + * Fetches a timestamp in a custom CUC format consisting of 4 bytes from the current position in the message */ - Time::CustomCUC_t readCustomCUCTimeStamp() { - Time::CustomCUC_t customCUC_t; + Time::DefaultCUC readDefaultCUCTimeStamp() { + auto time = readUint32(); + std::chrono::duration<uint32_t, Time::DefaultCUC::Ratio> duration(time); - customCUC_t.elapsed100msTicks = readUint64(); - return customCUC_t; + return Time::DefaultCUC(duration); } /** @@ -729,8 +741,8 @@ inline void Message::append(const double& value) { appendDouble(value); } template <> -inline void Message::append(const Time::CustomCUC_t& timeCUC) { - appendCustomCUCTimeStamp(timeCUC); +inline void Message::append(const Time::DefaultCUC& timeCUC) { + appendDefaultCUCTimeStamp(timeCUC); } template <> inline void Message::append(const Time::RelativeTime& value) { @@ -794,8 +806,8 @@ inline double Message::read() { return readDouble(); } template <> -inline Time::CustomCUC_t Message::read() { - return readCustomCUCTimeStamp(); +inline Time::DefaultCUC Message::read() { + return readDefaultCUCTimeStamp(); } template <> inline Time::RelativeTime Message::read() { diff --git a/inc/Services/ParameterStatisticsService.hpp b/inc/Services/ParameterStatisticsService.hpp index ba6d895f6d53ad954a8e362a46fe43ca767fe6ec..c686558ebb74133a10155a3bedeb5e3d7fc8ec57 100644 --- a/inc/Services/ParameterStatisticsService.hpp +++ b/inc/Services/ParameterStatisticsService.hpp @@ -21,7 +21,7 @@ private: * The time at which the evaluation of statistics is initialized. It is basically the time when the statistics * are reset. */ - Time::CustomCUC_t evaluationStartTime; + Time::DefaultCUC evaluationStartTime; /** * true means that the periodic statistics reporting is enabled diff --git a/inc/Services/TimeBasedSchedulingService.hpp b/inc/Services/TimeBasedSchedulingService.hpp index 10561c1e69fbd4af0ed81062d6ddc10327df87e6..a3816071866db8f99f7ab014eb0026024ab9fc93 100644 --- a/inc/Services/TimeBasedSchedulingService.hpp +++ b/inc/Services/TimeBasedSchedulingService.hpp @@ -81,7 +81,7 @@ private: struct ScheduledActivity { Message request; ///< Hold the received command request RequestID requestID; ///< Request ID, characteristic of the definition - Time::CustomCUC_t requestReleaseTime{0}; ///< Keep the command release time + Time::DefaultCUC requestReleaseTime{0}; ///< Keep the command release time }; /** @@ -148,7 +148,7 @@ public: * This function executes the next activity and removes it from the list. * @return the requestReleaseTime of next activity to be executed after this time */ - Time::CustomCUC_t executeScheduledActivity(Time::CustomCUC_t currentTime); + Time::DefaultCUC executeScheduledActivity(Time::DefaultCUC currentTime); /** * @brief TC[11,1] enable the time-based schedule execution function diff --git a/inc/Time/Time.hpp b/inc/Time/Time.hpp index 60d4a969588dafa61092e889a389dcea6c87c166..1b4fb89dc15b8d2665b91485c9a756e96f9ecaf2 100644 --- a/inc/Time/Time.hpp +++ b/inc/Time/Time.hpp @@ -263,59 +263,11 @@ namespace Time { return (year % 400) == 0; } - struct CustomCUC_t { - uint64_t elapsed100msTicks = 0; - - /** - * @return The time represented in milliseconds elapsed from the epoch - */ - uint64_t getMs() { - return elapsed100msTicks * 100; - } - }; - /** * A time shift for scheduled activities measured in seconds */ typedef int64_t RelativeTime; - inline Time::CustomCUC_t operator+(const Time::CustomCUC_t time, RelativeTime relativeTime) { - return Time::CustomCUC_t{time.elapsed100msTicks + relativeTime * 10}; - } - - inline Time::CustomCUC_t operator-(const Time::CustomCUC_t time, RelativeTime relativeTime) { - return Time::CustomCUC_t{time.elapsed100msTicks - relativeTime * 10}; - } - - inline Time::CustomCUC_t& operator+=(Time::CustomCUC_t& time, RelativeTime relativeTime) { - time.elapsed100msTicks += relativeTime * 10; - return time; - } - - inline Time::CustomCUC_t operator-(Time::CustomCUC_t time1, Time::CustomCUC_t time2) { - return Time::CustomCUC_t{time1.elapsed100msTicks - time2.elapsed100msTicks}; - } - - inline Time::CustomCUC_t operator+(Time::CustomCUC_t time1, Time::CustomCUC_t time2) { - return Time::CustomCUC_t{time1.elapsed100msTicks + time2.elapsed100msTicks}; - } - - inline bool operator<(Time::CustomCUC_t time1, Time::CustomCUC_t time2) { - return time1.elapsed100msTicks < time2.elapsed100msTicks; - } - - inline bool operator>(Time::CustomCUC_t time1, Time::CustomCUC_t time2) { - return time1.elapsed100msTicks > time2.elapsed100msTicks; - } - - inline bool operator==(const Time::CustomCUC_t time1, Time::CustomCUC_t time2) { - return time1.elapsed100msTicks == time2.elapsed100msTicks; - } - - inline bool operator>=(Time::CustomCUC_t time1, Time::CustomCUC_t time2) { - return time1.elapsed100msTicks >= time2.elapsed100msTicks; - } - /** * is_duration definition to check if a variable is std::chrono::duration */ diff --git a/inc/Time/TimeStamp.hpp b/inc/Time/TimeStamp.hpp index 5b23764884b3710b56fe002d9674040fc66d9766..dbdefaf10008d68a6b6fa920d4d53d4e048c2221 100644 --- a/inc/Time/TimeStamp.hpp +++ b/inc/Time/TimeStamp.hpp @@ -102,7 +102,10 @@ private: /** * The maximum value of the base type (seconds, larger or smaller) that can fit in @ref taiCounter */ - static constexpr uint64_t MaxBase = (BaseBytes == 8) ? std::numeric_limits<uint64_t>::max() : (1UL << 8 * BaseBytes) - 1; + static constexpr uint64_t MaxBase = + (BaseBytes == 8) + ? std::numeric_limits<uint64_t>::max() + : (uint64_t{1} << 8 * BaseBytes) - 1; /** * The maximum number of seconds since epoch that can be represented in this class @@ -130,14 +133,6 @@ public: */ explicit TimeStamp(uint64_t taiSecondsFromEpoch); - /** - * Initialize the TimeStamp from a count of 100ms ticks from epoch in TAI (leap seconds not accounted) - * - * @param customCUCTimestamp An struct containing a 64 bit unsigned number of 100ms - * ticks from the custom @ref Time::Epoch - */ - explicit TimeStamp(Time::CustomCUC_t customCUCTimestamp); - /** * Initialize the TimeStamp from the bytes of a CUC time stamp * @@ -179,14 +174,6 @@ public: */ TAICounter_t asTAIseconds(); - /** - * Get the representation as a struct containing 100ms ticks from epoch in TAI - * - * @return An struct containing a 64 bit unsigned number of 100ms - * ticks from the custom @ref Time::Epoch. This function is explicitly defined. - */ - Time::CustomCUC_t asCustomCUCTimestamp(); - /** * Get the representation as seconds from epoch in TAI, for a floating-point representation. * For an integer result, see the overloaded @ref asTAIseconds function. @@ -203,15 +190,20 @@ public: * @warning This function does not perform overflow calculations. It is up to the user to ensure that the types are compatible so that no overflow occurs. */ template <class Duration = std::chrono::seconds> - Duration asDuration(); + Duration asDuration() const; /** - * Get the representation as CUC formatted bytes - * - * @return The TimeStamp, represented in the CCSDS CUC format + * Get the representation as CUC formatted bytes, including the header (P-field and T-field) */ etl::array<uint8_t, Time::CUCTimestampMaximumSize> formatAsCUC(); + /** + * Get the representation as CUC formatted bytes, without the header (T-field only) + */ + TAICounter_t formatAsBytes() const { + return taiCounter; + } + /** * Get the representation as a UTC timestamp * @@ -219,6 +211,83 @@ public: */ UTCTimestamp toUTCtimestamp(); + /** + * Get the maximum timestamp that can be represented by this class + * + * Can be used to represent null or infinite amounts of time + */ + static TimeStamp<BaseBytes, FractionBytes, Num, Denom> max() { + TimeStamp<BaseBytes, FractionBytes, Num, Denom> timestamp; + timestamp.taiCounter = std::numeric_limits<TAICounter_t>::max(); + return timestamp; + } + + /** + * Adds any arbitrary duration to a timestamp. + * + * You can play with default C++ durations with this function: + * ```cpp + * using namespace std::literals; + * + * timestamp + std::chrono::seconds(5); // adds 5 seconds + * timestamp + std::chrono::milliseconds(500); // adds 5 milliseconds + * timestamp + 60s; // adds 60 seconds + */ + template <class Duration, typename = std::enable_if_t<Time::is_duration_v<Duration>>> + TimeStamp<BaseBytes, FractionBytes, Num, Denom> operator+(const Duration& duration) const { + auto output = *this; + output += duration; + return output; + } + + template <class Duration, typename = std::enable_if_t<Time::is_duration_v<Duration>>> + TimeStamp<BaseBytes, FractionBytes, Num, Denom>& operator+=(const Duration& duration) { + if (duration < Duration::zero()) { + taiCounter -= std::chrono::duration_cast<RawDuration>(-duration).count(); + } else { + taiCounter += std::chrono::duration_cast<RawDuration>(duration).count(); + } + + return *this; + } + + template <class Duration, typename = std::enable_if_t<Time::is_duration_v<Duration>>> + TimeStamp<BaseBytes, FractionBytes, Num, Denom> operator-(const Duration& duration) const { + auto output = *this; + output -= duration; + return output; + } + + template <class Duration, typename = std::enable_if_t<Time::is_duration_v<Duration>>> + TimeStamp<BaseBytes, FractionBytes, Num, Denom>& operator-=(const Duration& duration) { + if (duration < Duration::zero()) { + taiCounter += std::chrono::duration_cast<RawDuration>(-duration).count(); + } else { + taiCounter -= std::chrono::duration_cast<RawDuration>(duration).count(); + } + + return *this; + } + + /** + * Subtraction between two timestamps. + * + * Given 2 absolute moments in time, returns the relative duration between them. + * @tparam Duration The duration returned is equal to the RawDuration of the first timestamp, + * but it's signed instead of unsigned, so that negative results can be represented. + */ + template < + uint8_t BaseBytesIn, uint8_t FractionBytesIn, int NumIn = 1, int DenomIn = 1, // Template parameters of the 2nd timestamp + class Duration = std::chrono::duration< // Create a new Duration based on our RawDuration... + typename std::make_signed<typename RawDuration::rep>::type, // the Duration base type is equal to the RawDuration, but converted to signed from unsigned + typename RawDuration::period>> + Duration operator-(const TimeStamp<BaseBytesIn, FractionBytesIn, NumIn, DenomIn>& operand) const { + Duration myDuration = asDuration<Duration>(); + Duration operandDuration = operand.template asDuration<Duration>(); + + return myDuration - operandDuration; + } + /** * @name Comparison operators between timestamps * @{ @@ -257,4 +326,23 @@ public: */ }; +namespace Time { + using DefaultCUC = TimeStamp<4, 0, 1, 10>; + + /** + * Creates a custom literal to specify timestamp ticks. + * + * For example, this code: + * ```cpp + * Time::DefaultCUC timestamp(1000_t); + * ``` + * will define a timestamp 1000 ticks from the epoch. + * + * The time amount of a "tick" is the period defined by the DefaultCUC::Ratio + */ + constexpr std::chrono::duration<uint32_t, DefaultCUC::Ratio> operator""_t(unsigned long long s) { + return std::chrono::duration<uint32_t, DefaultCUC::Ratio>(s); + } +} // namespace Time + #include "TimeStamp.tpp" diff --git a/inc/Time/TimeStamp.tpp b/inc/Time/TimeStamp.tpp index 35a62061aaf6863366327a35be2f45b4e68b526f..4df8d7990812fb72205165167f16d5022f88291a 100644 --- a/inc/Time/TimeStamp.tpp +++ b/inc/Time/TimeStamp.tpp @@ -1,4 +1,5 @@ #include <cmath> +#include "TimeStamp.hpp" template <uint8_t BaseBytes, uint8_t FractionBytes, int Num, int Denom> constexpr bool TimeStamp<BaseBytes, FractionBytes, Num, Denom>::areSecondsValid(TimeStamp::TAICounter_t seconds) { @@ -15,15 +16,6 @@ TimeStamp<BaseBytes, FractionBytes, Num, Denom>::TimeStamp(uint64_t taiSecondsFr taiCounter = std::chrono::duration_cast<RawDuration>(duration).count(); } -template <uint8_t BaseBytes, uint8_t FractionBytes, int Num, int Denom> -TimeStamp<BaseBytes, FractionBytes, Num, Denom>::TimeStamp(Time::CustomCUC_t customCUCTimestamp) { - //TODO Remove CustomCUC_t class - TimeStamp<8, 0, 1, 10> input; - input.taiCounter = customCUCTimestamp.elapsed100msTicks; - - new (this) TimeStamp<BaseBytes, FractionBytes, Num, Denom>(input); -} - template <uint8_t BaseBytes, uint8_t FractionBytes, int Num, int Denom> TimeStamp<BaseBytes, FractionBytes, Num, Denom>::TimeStamp(etl::array<uint8_t, Time::CUCTimestampMaximumSize> timestamp) { // process header @@ -106,13 +98,6 @@ TimeStamp<BaseBytes, FractionBytes, Num, Denom>::asTAIseconds() { return std::chrono::duration_cast<ToDuration>(duration).count(); } -template <uint8_t BaseBytes, uint8_t FractionBytes, int Num, int Denom> -Time::CustomCUC_t TimeStamp<BaseBytes, FractionBytes, Num, Denom>::asCustomCUCTimestamp() { - //TODO: Remove CustomCUC_t class - TimeStamp<8, 0, 1, 10> converted(*this); - return {converted.taiCounter}; -} - template <uint8_t BaseBytes, uint8_t FractionBytes, int Num, int Denom> template <typename T> T TimeStamp<BaseBytes, FractionBytes, Num, Denom>::asTAIseconds() { @@ -179,7 +164,7 @@ TimeStamp<BaseBytes, FractionBytes, Num, Denom>::TimeStamp(TimeStamp<BaseBytesIn template <uint8_t BaseBytes, uint8_t FractionBytes, int Num, int Denom> template <class Duration> -Duration TimeStamp<BaseBytes, FractionBytes, Num, Denom>::asDuration() { +Duration TimeStamp<BaseBytes, FractionBytes, Num, Denom>::asDuration() const { auto duration = RawDuration(taiCounter); return std::chrono::duration_cast<Duration>(duration); diff --git a/src/Helpers/Statistic.cpp b/src/Helpers/Statistic.cpp index 9e43d8c7413fad77017b2b0c3631021e32999a86..672f46718157b434a4997d97f2a83e7824dbcc6b 100644 --- a/src/Helpers/Statistic.cpp +++ b/src/Helpers/Statistic.cpp @@ -4,11 +4,11 @@ void Statistic::updateStatistics(double value) { if (value > max) { max = value; - timeOfMaxValue = TimeGetter::getCurrentTimeCustomCUC(); + timeOfMaxValue = TimeGetter::getCurrentTimeDefaultCUC(); } if (value < min) { min = value; - timeOfMinValue = TimeGetter::getCurrentTimeCustomCUC(); + timeOfMinValue = TimeGetter::getCurrentTimeDefaultCUC(); } if (sampleCounter + 1 > 0) { mean = (mean * sampleCounter + value) / (sampleCounter + 1); @@ -43,8 +43,8 @@ void Statistic::setSelfSamplingInterval(uint16_t samplingInterval) { void Statistic::resetStatistics() { max = -std::numeric_limits<double>::infinity(); min = std::numeric_limits<double>::infinity(); - timeOfMaxValue.elapsed100msTicks = 0; - timeOfMinValue.elapsed100msTicks = 0; + timeOfMaxValue = Time::DefaultCUC(0); + timeOfMinValue = Time::DefaultCUC(0); mean = 0; sumOfSquares = 0; sampleCounter = 0; @@ -52,6 +52,6 @@ void Statistic::resetStatistics() { bool Statistic::statisticsAreInitialized() { return (sampleCounter == 0 and mean == 0 and sumOfSquares == 0 and - timeOfMaxValue.elapsed100msTicks == 0 and timeOfMinValue.elapsed100msTicks == 0 and + timeOfMaxValue == Time::DefaultCUC(0) and timeOfMinValue == Time::DefaultCUC(0) and max == -std::numeric_limits<double>::infinity() and min == std::numeric_limits<double>::infinity()); } diff --git a/src/MessageParser.cpp b/src/MessageParser.cpp index 5d2de01b244c0be17b8fa2e732de2638198f1f82..7ae9d4ac9f4322390013f4e1547990746d5736b7 100644 --- a/src/MessageParser.cpp +++ b/src/MessageParser.cpp @@ -173,7 +173,7 @@ String<CCSDSMaxMessageSize> MessageParser::composeECSS(const Message& message, u header[4] = static_cast<uint8_t>(message.messageTypeCounter & 0xffU); header[5] = message.applicationId >> 8U; // DestinationID header[6] = message.applicationId; - uint64_t ticks = TimeGetter::getCurrentTimeCustomCUC().elapsed100msTicks; + uint32_t ticks = TimeGetter::getCurrentTimeDefaultCUC().formatAsBytes(); header[7] = (ticks >> 24) & 0xffU; header[8] = (ticks >> 16) & 0xffU; header[9] = (ticks >> 8) & 0xffU; diff --git a/src/Platform/x86/TimeGetter.cpp b/src/Platform/x86/TimeGetter.cpp index ea34fbce5d3e3af4eb3e106cd986e04fea97a498..acff1688c887152d17d5b09fa621fd86c807be62 100644 --- a/src/Platform/x86/TimeGetter.cpp +++ b/src/Platform/x86/TimeGetter.cpp @@ -9,9 +9,7 @@ UTCTimestamp TimeGetter::getCurrentTimeUTC() { return currentTime; } -Time::CustomCUC_t TimeGetter::getCurrentTimeCustomCUC() { +Time::DefaultCUC TimeGetter::getCurrentTimeDefaultCUC() { UTCTimestamp timeUTC = getCurrentTimeUTC(); - TimeStamp<Time::CUCSecondsBytes, Time::CUCFractionalBytes> timeCUC(timeUTC); - Time::CustomCUC_t CUCtime = timeCUC.asCustomCUCTimestamp(); - return CUCtime; + return Time::DefaultCUC(timeUTC); } diff --git a/src/Services/ParameterStatisticsService.cpp b/src/Services/ParameterStatisticsService.cpp index a9336696d9cca33f1f5e1a68cc906b49c640c694..1f452f171c6449ecfdafa9f92eac99364bb81877 100644 --- a/src/Services/ParameterStatisticsService.cpp +++ b/src/Services/ParameterStatisticsService.cpp @@ -3,7 +3,7 @@ #include "ServicePool.hpp" #include "Services/ParameterStatisticsService.hpp" -ParameterStatisticsService::ParameterStatisticsService() : evaluationStartTime(TimeGetter::getCurrentTimeCustomCUC()) { +ParameterStatisticsService::ParameterStatisticsService() : evaluationStartTime(TimeGetter::getCurrentTimeDefaultCUC()) { initializeStatisticsMap(); serviceType = ServiceType; } @@ -28,7 +28,7 @@ void ParameterStatisticsService::reportParameterStatistics(bool reset) { void ParameterStatisticsService::parameterStatisticsReport() { Message report = createTM(ParameterStatisticsReport); report.append(evaluationStartTime); - auto evaluationStopTime = TimeGetter::getCurrentTimeCustomCUC(); + auto evaluationStopTime = TimeGetter::getCurrentTimeDefaultCUC(); report.append(evaluationStopTime); uint16_t numOfValidParameters = 0; @@ -63,7 +63,7 @@ void ParameterStatisticsService::resetParameterStatistics() { for (auto& it: statisticsMap) { it.second.resetStatistics(); } - evaluationStartTime = TimeGetter::getCurrentTimeCustomCUC(); + evaluationStartTime = TimeGetter::getCurrentTimeDefaultCUC(); } void ParameterStatisticsService::enablePeriodicStatisticsReporting(Message& request) { diff --git a/src/Services/TimeBasedSchedulingService.cpp b/src/Services/TimeBasedSchedulingService.cpp index 0173dcc6267f97c60da0e9fc2c94785e6c692e4a..811334b9ce437725a938cbca04448eeb3a6e7222 100644 --- a/src/Services/TimeBasedSchedulingService.cpp +++ b/src/Services/TimeBasedSchedulingService.cpp @@ -7,7 +7,7 @@ TimeBasedSchedulingService::TimeBasedSchedulingService() { serviceType = TimeBasedSchedulingService::ServiceType; } -Time::CustomCUC_t TimeBasedSchedulingService::executeScheduledActivity(Time::CustomCUC_t currentTime) { +Time::DefaultCUC TimeBasedSchedulingService::executeScheduledActivity(Time::DefaultCUC currentTime) { if (currentTime >= scheduledActivities.front().requestReleaseTime && !scheduledActivities.empty()) { if (scheduledActivities.front().requestID.applicationID == ApplicationId) { MessageParser::execute(scheduledActivities.front().request); @@ -18,9 +18,7 @@ Time::CustomCUC_t TimeBasedSchedulingService::executeScheduledActivity(Time::Cus if (!scheduledActivities.empty()) { return scheduledActivities.front().requestReleaseTime; } else { - Time::CustomCUC_t infinity; - infinity.elapsed100msTicks = std::numeric_limits<decltype(infinity.elapsed100msTicks)>::max(); - return infinity; + return Time::DefaultCUC::max(); } } @@ -48,9 +46,9 @@ void TimeBasedSchedulingService::insertActivities(Message& request) { uint16_t iterationCount = request.readUint16(); while (iterationCount-- != 0) { // todo: Get the group ID first, if groups are used - Time::CustomCUC_t currentTime = TimeGetter::getCurrentTimeCustomCUC(); + Time::DefaultCUC currentTime = TimeGetter::getCurrentTimeDefaultCUC(); - Time::CustomCUC_t releaseTime = request.readCustomCUCTimeStamp(); + Time::DefaultCUC releaseTime = request.readDefaultCUCTimeStamp(); if ((scheduledActivities.available() == 0) || (releaseTime < (currentTime + ECSSTimeMarginForActivation))) { ErrorHandler::reportError(request, ErrorHandler::InstructionExecutionStartError); request.skipBytes(ECSSTCRequestStringSize); @@ -77,7 +75,7 @@ void TimeBasedSchedulingService::insertActivities(Message& request) { void TimeBasedSchedulingService::timeShiftAllActivities(Message& request) { request.assertTC(TimeBasedSchedulingService::ServiceType, TimeBasedSchedulingService::MessageType::TimeShiftALlScheduledActivities); - Time::CustomCUC_t current_time = TimeGetter::getCurrentTimeCustomCUC(); + Time::DefaultCUC current_time = TimeGetter::getCurrentTimeDefaultCUC(); const auto releaseTimes = etl::minmax_element(scheduledActivities.begin(), scheduledActivities.end(), @@ -86,11 +84,11 @@ void TimeBasedSchedulingService::timeShiftAllActivities(Message& request) { }); // todo: Define what the time format is going to be Time::RelativeTime relativeOffset = request.readRelativeTime(); - if ((releaseTimes.first->requestReleaseTime + relativeOffset) < (current_time + ECSSTimeMarginForActivation)) { + if ((releaseTimes.first->requestReleaseTime + std::chrono::seconds(relativeOffset)) < (current_time + ECSSTimeMarginForActivation)) { ErrorHandler::reportError(request, ErrorHandler::SubServiceExecutionStartError); } else { for (auto& activity: scheduledActivities) { - activity.requestReleaseTime += relativeOffset; + activity.requestReleaseTime += std::chrono::seconds(relativeOffset); } } } @@ -98,9 +96,9 @@ void TimeBasedSchedulingService::timeShiftAllActivities(Message& request) { void TimeBasedSchedulingService::timeShiftActivitiesByID(Message& request) { request.assertTC(TimeBasedSchedulingService::ServiceType, TimeBasedSchedulingService::MessageType::TimeShiftActivitiesById); - Time::CustomCUC_t current_time = TimeGetter::getCurrentTimeCustomCUC(); + Time::DefaultCUC current_time = TimeGetter::getCurrentTimeDefaultCUC(); - Time::RelativeTime relativeOffset = request.readRelativeTime(); + auto relativeOffset = std::chrono::seconds(request.readRelativeTime()); uint16_t iterationCount = request.readUint16(); while (iterationCount-- != 0) { RequestID receivedRequestID; @@ -159,7 +157,7 @@ void TimeBasedSchedulingService::detailReportAllActivities(Message& request) { for (auto& activity: scheduledActivities) { // todo: append sub-schedule and group ID if they are defined - report.appendCustomCUCTimeStamp(activity.requestReleaseTime); + report.appendDefaultCUCTimeStamp(activity.requestReleaseTime); report.appendString(MessageParser::composeECSS(activity.request)); } storeMessage(report); @@ -195,7 +193,7 @@ void TimeBasedSchedulingService::detailReportActivitiesByID(Message& request) { // todo: append sub-schedule and group ID if they are defined report.appendUint16(static_cast<uint16_t>(matchedActivities.size())); for (auto& match: matchedActivities) { - report.appendCustomCUCTimeStamp(match.requestReleaseTime); // todo: Replace with the time parser + report.appendDefaultCUCTimeStamp(match.requestReleaseTime); // todo: Replace with the time parser report.appendString(MessageParser::composeECSS(match.request)); } storeMessage(report); @@ -231,7 +229,7 @@ void TimeBasedSchedulingService::summaryReportActivitiesByID(Message& request) { report.appendUint16(static_cast<uint16_t>(matchedActivities.size())); for (auto& match: matchedActivities) { // todo: append sub-schedule and group ID if they are defined - report.appendCustomCUCTimeStamp(match.requestReleaseTime); + report.appendDefaultCUCTimeStamp(match.requestReleaseTime); report.appendUint8(match.requestID.sourceID); report.appendUint16(match.requestID.applicationID); report.appendUint16(match.requestID.sequenceCount); diff --git a/test/Helpers/StatisticTests.cpp b/test/Helpers/StatisticTests.cpp index 75d69c0ce115b8438dbb0d40d0df6ed071dd28a4..5fb8a3e8dd1b93ec2a72cd3f1adcdd0a68f53b22 100644 --- a/test/Helpers/StatisticTests.cpp +++ b/test/Helpers/StatisticTests.cpp @@ -52,9 +52,9 @@ TEST_CASE("Appending of statistics to message") { stat.appendStatisticsToMessage(report); REQUIRE(report.readFloat() == 8.35f); - REQUIRE(report.readUint64() == 86769000); // dummy time value + REQUIRE(report.readUint32() == 86769000); // dummy time value REQUIRE(report.readFloat() == 1.09f); - REQUIRE(report.readUint64() == 86769000); + REQUIRE(report.readUint32() == 86769000); REQUIRE(report.readFloat() == Catch::Approx(4.99501).epsilon(0.00001)); REQUIRE(report.readFloat() == Catch::Approx(2.76527).epsilon(0.00001)); } diff --git a/test/MessageParserTests.cpp b/test/MessageParserTests.cpp index 4ec0f8ff790a03d5afe4d8b94c072d435eebfcb7..b513b90945df366054584b45e5579207100bd89e 100644 --- a/test/MessageParserTests.cpp +++ b/test/MessageParserTests.cpp @@ -51,12 +51,11 @@ TEST_CASE("TM message parsing", "[MessageParser]") { uint8_t packet[] = {0x08, 0x02, 0xc0, 0x4d, 0x00, 0x12, 0x20, 0x16, 0x11,0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x68, 0x69}; - //save time - uint64_t tenths = TimeGetter::getCurrentTimeCustomCUC().elapsed100msTicks; - packet[13] = (tenths >> 24) & 0xFF; - packet[14] = (tenths >> 16) & 0xFF; - packet[15] = (tenths >> 8) & 0xFF; - packet[16] = (tenths) & 0xFF; + uint32_t time = TimeGetter::getCurrentTimeDefaultCUC().formatAsBytes(); + packet[13] = (time >> 24) & 0xFF; + packet[14] = (time >> 16) & 0xFF; + packet[15] = (time >> 8) & 0xFF; + packet[16] = (time) & 0xFF; Message message = MessageParser::parse(packet, 24); CHECK(message.packetType == Message::TM); @@ -70,7 +69,7 @@ TEST_CASE("TM message parsing", "[MessageParser]") { // Add ECSS and CCSDS header String<CCSDSMaxMessageSize> createdPacket = MessageParser::compose(message); uint32_t messageTime = (createdPacket[16] & 0xFF) | ((createdPacket[15] & 0xFF ) << 8) | ((createdPacket[14] & 0xFF) << 16) | ((createdPacket[13] & 0xFF ) << 24); - CHECK(messageTime == tenths); + CHECK(messageTime == time); } @@ -78,12 +77,11 @@ TEST_CASE("TM Message parsing into a string", "[MessageParser]") { uint8_t wantedPacket[] = {0x08, 0x02, 0xc0, 0x4d, 0x00, 0x11, 0x20, 0x16, 0x11,0x00, 0x00,0x00, 0x02,0x00, 0x00,0x00, 0x00, 0x68,0x65, 0x6c, 0x6c, 0x6f, 0x68, 0x69}; - //save time - uint64_t tenths = TimeGetter::getCurrentTimeCustomCUC().elapsed100msTicks; - wantedPacket[13] = (tenths >> 24) & 0xFF; - wantedPacket[14] = (tenths >> 16) & 0xFF; - wantedPacket[15] = (tenths >> 8) & 0xFF; - wantedPacket[16] = (tenths) & 0xFF; + uint32_t time = TimeGetter::getCurrentTimeDefaultCUC().formatAsBytes(); + wantedPacket[13] = (time >> 24) & 0xFF; + wantedPacket[14] = (time >> 16) & 0xFF; + wantedPacket[15] = (time >> 8) & 0xFF; + wantedPacket[16] = (time) & 0xFF; Message message; message.packetType = Message::TM; diff --git a/test/MessageTests.cpp b/test/MessageTests.cpp index 23d2511f6f007d292c7a35176742c16a1c188fb2..27ff3886a7e2666ec752fc9021b359e805684a4e 100644 --- a/test/MessageTests.cpp +++ b/test/MessageTests.cpp @@ -176,40 +176,41 @@ TEST_CASE("Test appending offset") { } TEST_CASE("Test appending a CUC timestamp") { + using namespace Time; + SECTION("Test 1") { - auto timeCUC = TimeGetter::getCurrentTimeCustomCUC(); - REQUIRE(timeCUC.elapsed100msTicks == 86769000); + auto timeCUC = TimeGetter::getCurrentTimeDefaultCUC(); + REQUIRE(timeCUC.formatAsBytes() == 86769000); Message message(0, 0, Message::TC, 0); - message.appendCustomCUCTimeStamp(timeCUC); + message.appendDefaultCUCTimeStamp(timeCUC); - REQUIRE(message.readUint64() == 86769000); + REQUIRE(message.readUint32() == 86769000); } SECTION("Test 2") { - Time::CustomCUC_t timeCUC; - timeCUC.elapsed100msTicks = 34511; + DefaultCUC timeCUC(34511_t); Message message(0, 0, Message::TC, 0); - message.appendCustomCUCTimeStamp(timeCUC); + message.appendDefaultCUCTimeStamp(timeCUC); - REQUIRE(message.readUint64() == 34511); + REQUIRE(message.readUint32() == 34511); } } TEST_CASE("Test reading a custom CUC timestamp") { + using namespace Time; /** * Append a custom CUC Time Stamp to a message object and check if is it read corretly */ - Time::CustomCUC_t timeCUC; - timeCUC.elapsed100msTicks = 34511; + DefaultCUC timeCUC(34511_t); Message message(0, 0, Message::TC, 0); - message.appendCustomCUCTimeStamp(timeCUC); + message.appendDefaultCUCTimeStamp(timeCUC); - auto returnTimeCUC = message.readCustomCUCTimeStamp(); + auto returnTimeCUC = message.readDefaultCUCTimeStamp(); - REQUIRE(returnTimeCUC.elapsed100msTicks == 34511); + REQUIRE(returnTimeCUC.formatAsBytes() == 34511); } TEST_CASE("Requirement 7.3.8 (Octet-string)", "[message][ecss]") { diff --git a/test/Parameters/LazyParameterTests.cpp b/test/Parameters/LazyParameterTests.cpp index 800c865c687a7a4350b6a4ccc4d7c98d8ead5583..ef291663fc136290ead8f9588aa1cc5c60524ee8 100644 --- a/test/Parameters/LazyParameterTests.cpp +++ b/test/Parameters/LazyParameterTests.cpp @@ -66,18 +66,20 @@ TEST_CASE("Lazy Parameter: Messages") { } TEST_CASE("Lazy Parameter: Complex Types") { - LazyParameter<Time::CustomCUC_t> parameter({100}); + using namespace Time; + + LazyParameter<Time::DefaultCUC> parameter(Time::DefaultCUC(100_t)); SECTION("Default value") { CHECK(parameter.getValue().has_value() == false); } SECTION("Set value") { - parameter.setGetter([]() -> Time::CustomCUC_t { - return {200}; + parameter.setGetter([]() -> Time::DefaultCUC { + return Time::DefaultCUC(200_t); }); - CHECK(parameter.getValue().value() == Time::CustomCUC_t{200}); + CHECK(parameter.getValue().value() == Time::DefaultCUC{200_t}); CHECK(parameter.getValueAsDouble() == 0); } } diff --git a/test/Services/ParameterStatisticsServiceTests.cpp b/test/Services/ParameterStatisticsServiceTests.cpp index 3ec7031866804325b5b35c9b3a8c0f6bf12d761b..25ae3c908379fff554f93e189be57bc00f29bfa7 100644 --- a/test/Services/ParameterStatisticsServiceTests.cpp +++ b/test/Services/ParameterStatisticsServiceTests.cpp @@ -40,25 +40,25 @@ TEST_CASE("Reporting of statistics") { Message report = ServiceTests::get(0); CHECK(report.serviceType == ParameterStatisticsService::ServiceType); CHECK(report.messageType == ParameterStatisticsService::MessageType::ParameterStatisticsReport); - CHECK(report.readUint64() == 86769000); // start time - CHECK(report.readUint64() == 86769000); // end time + CHECK(report.readUint32() == 86769000); // start time + CHECK(report.readUint32() == 86769000); // end time CHECK(report.readUint16() == 2); // number of parameters reported // Parameter B CHECK(report.readUint16() == 5); // ID-2 CHECK(report.readUint16() == 6); // number of samples CHECK(report.readFloat() == 13); // max value - CHECK(report.readUint64() == 86769000); // max time + CHECK(report.readUint32() == 86769000); // max time CHECK(report.readFloat() == 3); // min value - CHECK(report.readUint64() == 86769000); // min time + CHECK(report.readUint32() == 86769000); // min time CHECK(report.readFloat() == 8); // mean CHECK(report.readFloat() == Catch::Approx(3.41565).epsilon(0.01)); // Parameter A CHECK(report.readUint16() == 7); // ID-1 CHECK(report.readUint16() == 3); // number of samples CHECK(report.readFloat() == 5); // max value - CHECK(report.readUint64() == 86769000); // max time + CHECK(report.readUint32() == 86769000); // max time CHECK(report.readFloat() == 1); // min value - CHECK(report.readUint64() == 86769000); // min time + CHECK(report.readUint32() == 86769000); // min time CHECK(report.readFloat() == 3); // mean CHECK(static_cast<int>(report.readFloat()) == 1); // stddev @@ -105,25 +105,25 @@ TEST_CASE("Reporting of statistics") { Message report = ServiceTests::get(0); CHECK(report.serviceType == ParameterStatisticsService::ServiceType); CHECK(report.messageType == ParameterStatisticsService::MessageType::ParameterStatisticsReport); - CHECK(report.readUint64() == 86769000); // start time - CHECK(report.readUint64() == 86769000); // end time + CHECK(report.readUint32() == 86769000); // start time + CHECK(report.readUint32() == 86769000); // end time CHECK(report.readUint16() == 2); // number of parameters reported // Parameter B CHECK(report.readUint16() == 5); // ID-2 CHECK(report.readUint16() == 6); // number of samples CHECK(report.readFloat() == 13); // max value - CHECK(report.readUint64() == 86769000); // max time + CHECK(report.readUint32() == 86769000); // max time CHECK(report.readFloat() == 3); // min value - CHECK(report.readUint64() == 86769000); // min time + CHECK(report.readUint32() == 86769000); // min time CHECK(report.readFloat() == 8); // mean CHECK(report.readFloat() == Catch::Approx(3.41565).epsilon(0.01)); // Parameter A CHECK(report.readUint16() == 7); // ID-1 CHECK(report.readUint16() == 3); // number of samples CHECK(report.readFloat() == 5); // max value - CHECK(report.readUint64() == 86769000); // max time + CHECK(report.readUint32() == 86769000); // max time CHECK(report.readFloat() == 1); // min value - CHECK(report.readUint64() == 86769000); // min time + CHECK(report.readUint32() == 86769000); // min time CHECK(report.readFloat() == 3); // mean CHECK(static_cast<int>(report.readFloat()) == 1); // stddev diff --git a/test/Services/TimeBasedSchedulingServiceTests.cpp b/test/Services/TimeBasedSchedulingServiceTests.cpp index 47e70433851769d1b795792c27f6ed5333d0d540..52dadcee9b40dde5f66b95a63dc835979fb890cc 100644 --- a/test/Services/TimeBasedSchedulingServiceTests.cpp +++ b/test/Services/TimeBasedSchedulingServiceTests.cpp @@ -5,6 +5,8 @@ #include <ctime> #include <vector> +using namespace std::chrono_literals; + /* * A namespace defined explicitly for the purposes of testing. This namespace contains a * structure, which has been declared as a friend in the TimeBasedSchedulingService class, so @@ -33,7 +35,7 @@ namespace unit_test { } // namespace unit_test Message testMessage1, testMessage2, testMessage3, testMessage4; -Time::CustomCUC_t currentTime = TimeGetter::getCurrentTimeCustomCUC(); // Get the current system time +Time::DefaultCUC currentTime = TimeGetter::getCurrentTimeDefaultCUC(); // Get the current system time bool messagesPopulated = false; // Indicate whether the test messages are initialized // Run this function to set the service up before moving on with further testing @@ -69,19 +71,19 @@ auto activityInsertion(TimeBasedSchedulingService& timeService) { receivedMessage.appendUint16(4); // Total number of requests // Test activity 1 - receivedMessage.appendCustomCUCTimeStamp(currentTime + 1556435); + receivedMessage.appendDefaultCUCTimeStamp(currentTime + 155643s); receivedMessage.appendMessage(testMessage1, ECSSTCRequestStringSize); // Test activity 2 - receivedMessage.appendCustomCUCTimeStamp(currentTime + 1957232); + receivedMessage.appendDefaultCUCTimeStamp(currentTime + 195723s); receivedMessage.appendMessage(testMessage2, ECSSTCRequestStringSize); // Test activity 3 - receivedMessage.appendCustomCUCTimeStamp(currentTime + 1726435); + receivedMessage.appendDefaultCUCTimeStamp(currentTime + 172643s); receivedMessage.appendMessage(testMessage3, ECSSTCRequestStringSize); // Test activity 4 - receivedMessage.appendCustomCUCTimeStamp(currentTime + 17248435); + receivedMessage.appendDefaultCUCTimeStamp(currentTime + 1724843s); receivedMessage.appendMessage(testMessage4, ECSSTCRequestStringSize); // Insert activities in the schedule. They have to be inserted sorted @@ -97,8 +99,8 @@ TEST_CASE("Execute the first activity, removes it from the list and return the r Services.reset(); auto scheduledActivities = activityInsertion(timeBasedService); - auto nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 1556435); - REQUIRE(nextActivityExecutionCUCTime == currentTime + 1726435); + auto nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 155643s); + REQUIRE(nextActivityExecutionCUCTime == currentTime + 172643s); Message receivedMessage(TimeBasedSchedulingService::ServiceType, TimeBasedSchedulingService::MessageType::DetailReportAllScheduledActivities, Message::TC, 1); timeBasedService.detailReportAllActivities(receivedMessage); @@ -106,27 +108,27 @@ TEST_CASE("Execute the first activity, removes it from the list and return the r uint16_t iterationCount = response.readUint16(); REQUIRE(iterationCount == 3); - nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 100); - REQUIRE(nextActivityExecutionCUCTime == currentTime + 1726435); + nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 10s); + REQUIRE(nextActivityExecutionCUCTime == currentTime + 172643s); - nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 1726435); - REQUIRE(nextActivityExecutionCUCTime == currentTime + 1957232); + nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 172643s); + REQUIRE(nextActivityExecutionCUCTime == currentTime + 195723s); timeBasedService.detailReportAllActivities(receivedMessage); response = ServiceTests::get(1); iterationCount = response.readUint16(); REQUIRE(iterationCount == 2); - nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 1957232); - REQUIRE(nextActivityExecutionCUCTime == currentTime + 17248435); + nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 195723s); + REQUIRE(nextActivityExecutionCUCTime == currentTime + 1724843s); timeBasedService.detailReportAllActivities(receivedMessage); response = ServiceTests::get(2); iterationCount = response.readUint16(); REQUIRE(iterationCount == 1); - nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 17248435); - REQUIRE(nextActivityExecutionCUCTime.elapsed100msTicks == std::numeric_limits<decltype(nextActivityExecutionCUCTime.elapsed100msTicks)>::max()); + nextActivityExecutionCUCTime = timeBasedService.executeScheduledActivity(currentTime + 1724843s); + REQUIRE(nextActivityExecutionCUCTime == Time::DefaultCUC::max()); timeBasedService.detailReportAllActivities(receivedMessage); response = ServiceTests::get(3); @@ -156,10 +158,10 @@ TEST_CASE("TC[11,4] Activity Insertion", "[service][st11]") { REQUIRE(scheduledActivities.size() == 4); - REQUIRE(scheduledActivities.at(0)->requestReleaseTime == currentTime + 1556435); - REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 1726435); - REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 1957232); - REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 17248435); + REQUIRE(scheduledActivities.at(0)->requestReleaseTime == currentTime + 155643s); + REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 172643s); + REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 195723s); + REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 1724843s); REQUIRE(testMessage1.bytesEqualWith(scheduledActivities.at(0)->request)); REQUIRE(testMessage3.bytesEqualWith(scheduledActivities.at(1)->request)); @@ -170,7 +172,7 @@ TEST_CASE("TC[11,4] Activity Insertion", "[service][st11]") { Message receivedMessage(TimeBasedSchedulingService::ServiceType, TimeBasedSchedulingService::MessageType::InsertActivities, Message::TC, 1); receivedMessage.appendUint16(1); // Total number of requests - receivedMessage.appendCustomCUCTimeStamp(currentTime - 1556435); + receivedMessage.appendDefaultCUCTimeStamp(currentTime - 155643s); MessageParser::execute(receivedMessage); //timeService.insertActivities(receivedMessage); REQUIRE(ServiceTests::thrownError(ErrorHandler::InstructionExecutionStartError)); @@ -190,10 +192,10 @@ TEST_CASE("TC[11,15] Time shift all scheduled activities", "[service][st11]") { CHECK(scheduledActivities.size() == 4); MessageParser::execute(receivedMessage); //timeService.timeShiftAllActivities(receivedMessage); - REQUIRE(scheduledActivities.at(0)->requestReleaseTime == currentTime + 1556435 - timeShift); - REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 1726435 - timeShift); - REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 1957232 - timeShift); - REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 17248435 - timeShift); + REQUIRE(scheduledActivities.at(0)->requestReleaseTime == currentTime + 155643s - std::chrono::seconds(timeShift)); + REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 172643s - std::chrono::seconds(timeShift)); + REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 195723s - std::chrono::seconds(timeShift)); + REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 1724843s - std::chrono::seconds(timeShift)); } SECTION("Negative Shift") { @@ -201,10 +203,10 @@ TEST_CASE("TC[11,15] Time shift all scheduled activities", "[service][st11]") { CHECK(scheduledActivities.size() == 4); MessageParser::execute(receivedMessage); //timeService.timeShiftAllActivities(receivedMessage); - REQUIRE(scheduledActivities.at(0)->requestReleaseTime == currentTime + 1556435 + timeShift); - REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 1726435 + timeShift); - REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 1957232 + timeShift); - REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 17248435 + timeShift); + REQUIRE(scheduledActivities.at(0)->requestReleaseTime == currentTime + 155643s + std::chrono::seconds(timeShift)); + REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 172643s + std::chrono::seconds(timeShift)); + REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 195723s + std::chrono::seconds(timeShift)); + REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 1724843s + std::chrono::seconds(timeShift)); } SECTION("Error throwing") { @@ -238,12 +240,12 @@ TEST_CASE("TC[11,7] Time shift activities by ID", "[service][st11]") { scheduledActivities = unit_test::Tester::scheduledActivities(timeBasedService); // Make sure the new value is inserted sorted - REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 1957232 + timeShift); + REQUIRE(scheduledActivities.at(3)->requestReleaseTime == currentTime + 195723s + std::chrono::seconds(timeShift)); REQUIRE(testMessage2.bytesEqualWith(scheduledActivities.at(3)->request)); } SECTION("Negative Shift") { - receivedMessage.appendRelativeTime(-250000); // Time-shift value + receivedMessage.appendRelativeTime(-25000); // Time-shift value receivedMessage.appendUint16(1); // Just one instruction to time-shift an activity receivedMessage.appendUint8(0); // Source ID is not implemented receivedMessage.appendUint16(testMessage2.applicationId); // todo: Remove the dummy app ID @@ -253,7 +255,7 @@ TEST_CASE("TC[11,7] Time shift activities by ID", "[service][st11]") { scheduledActivities = unit_test::Tester::scheduledActivities(timeBasedService); // Output should be sorted - REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 1957232 - 250000); + REQUIRE(scheduledActivities.at(1)->requestReleaseTime == currentTime + 195723s - 25000s); REQUIRE(testMessage2.bytesEqualWith(scheduledActivities.at(1)->request)); } @@ -311,7 +313,7 @@ TEST_CASE("TC[11,9] Detail report scheduled activities by ID", "[service][st11]" uint16_t iterationCount = response.readUint16(); CHECK(iterationCount == 2); for (uint16_t i = 0; i < iterationCount; i++) { - Time::CustomCUC_t receivedReleaseTime = response.readCustomCUCTimeStamp(); + Time::DefaultCUC receivedReleaseTime = response.readDefaultCUCTimeStamp(); Message receivedTCPacket; uint8_t receivedDataStr[ECSSTCRequestStringSize]; @@ -368,7 +370,7 @@ TEST_CASE("TC[11,12] Summary report scheduled activities by ID", "[service][st11 uint16_t iterationCount = response.readUint16(); for (uint16_t i = 0; i < iterationCount; i++) { - Time::CustomCUC_t receivedReleaseTime = response.readCustomCUCTimeStamp(); + Time::DefaultCUC receivedReleaseTime = response.readDefaultCUCTimeStamp(); uint8_t receivedSourceID = response.readUint8(); uint16_t receivedApplicationID = response.readUint16(); uint16_t receivedSequenceCount = response.readUint16(); @@ -414,7 +416,7 @@ TEST_CASE("TC[11,16] Detail report all scheduled activities", "[service][st11]") REQUIRE(iterationCount == scheduledActivities.size()); for (uint16_t i = 0; i < iterationCount; i++) { - Time::CustomCUC_t receivedReleaseTime = response.readCustomCUCTimeStamp(); + Time::DefaultCUC receivedReleaseTime = response.readDefaultCUCTimeStamp(); Message receivedTCPacket; uint8_t receivedDataStr[ECSSTCRequestStringSize]; @@ -446,7 +448,7 @@ TEST_CASE("TC[11,5] Activity deletion by ID", "[service][st11]") { scheduledActivities = unit_test::Tester::scheduledActivities(timeBasedService); REQUIRE(scheduledActivities.size() == 3); - REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 17248435); + REQUIRE(scheduledActivities.at(2)->requestReleaseTime == currentTime + 1724843s); REQUIRE(testMessage4.bytesEqualWith(scheduledActivities.at(2)->request)); } diff --git a/test/TestPlatform.cpp b/test/TestPlatform.cpp index a2a2d80f1fb09d8aed88242b88a8e35f516d210d..ddb8aad9a20aa0ebd369a056d667234ed34be1d9 100644 --- a/test/TestPlatform.cpp +++ b/test/TestPlatform.cpp @@ -18,11 +18,10 @@ UTCTimestamp TimeGetter::getCurrentTimeUTC() { return currentTime; } -Time::CustomCUC_t TimeGetter::getCurrentTimeCustomCUC() { +Time::DefaultCUC TimeGetter::getCurrentTimeDefaultCUC() { UTCTimestamp timeUTC = getCurrentTimeUTC(); - TimeStamp<Time::CUCSecondsBytes, Time::CUCFractionalBytes> timeCUC(timeUTC); - Time::CustomCUC_t CUCtime = timeCUC.asCustomCUCTimestamp(); - return CUCtime; + Time::DefaultCUC timeCUC(timeUTC); + return timeCUC; } // Explicit template specializations for the logError() function diff --git a/test/Time/TimeFormatsTests.cpp b/test/Time/TimeFormatsTests.cpp index c0134afe5d080b425d5a822a99d531589f41c43e..c7c0720930c619335c5fff1c7d323d032a38e525 100644 --- a/test/Time/TimeFormatsTests.cpp +++ b/test/Time/TimeFormatsTests.cpp @@ -65,14 +65,14 @@ TEST_CASE("UTC timestamp addition") { } TEST_CASE("CUC Custom Timestamp as Parameter") { - Time::CustomCUC_t time; - time.elapsed100msTicks = 999; + using namespace Time; + DefaultCUC time(999_t); - auto parameter = Parameter<Time::CustomCUC_t>(time); + auto parameter = Parameter<DefaultCUC>(time); auto message = Message(0, 0, Message::TC); parameter.appendValueToMessage(message); - CHECK(message.dataSize == 8); + CHECK(message.dataSize == 4); parameter.setValueFromMessage(message); CHECK(time == parameter.getValue()); diff --git a/test/Time/TimeStampTests.cpp b/test/Time/TimeStampTests.cpp index 9d2b52c40873e7abde9a129b01eb19feb2cdeb4d..f5338de0d5cc600cb0bfcd0967229aeac60658b0 100644 --- a/test/Time/TimeStampTests.cpp +++ b/test/Time/TimeStampTests.cpp @@ -91,38 +91,39 @@ TEST_CASE("Conversion between CUC formats") { TEST_CASE("Use of custom Acubesat CUC format") { SECTION("Check forward conversion") { - Time::CustomCUC_t customCUC1 = {1001}; - TimeStamp<3, 0> time1(customCUC1); + using namespace Time; + DefaultCUC defaultCUC1(1001_t); + TimeStamp<3, 0> time1(defaultCUC1); CHECK(time1.asTAIseconds() == 100); - CHECK(time1.asCustomCUCTimestamp().elapsed100msTicks == 1000); - TimeStamp<3, 2> time2(customCUC1); + CHECK(DefaultCUC(time1).formatAsBytes() == 1000); + TimeStamp<3, 2> time2(defaultCUC1); CHECK(time2.asTAIseconds() == 100); - CHECK(time2.asCustomCUCTimestamp().elapsed100msTicks == 1001); + CHECK(DefaultCUC(time2).formatAsBytes() == 1001); // check rounding errors - Time::CustomCUC_t customCUC2 = {1004}; - TimeStamp<3, 0> time3(customCUC2); + Time::DefaultCUC defaultCUC2(1004_t); + TimeStamp<3, 0> time3(defaultCUC2); CHECK(time3.asTAIseconds() == 100); - CHECK(time3.asCustomCUCTimestamp().elapsed100msTicks == 1000); - TimeStamp<3, 2> time4(customCUC2); + CHECK(DefaultCUC(time3).formatAsBytes() == 1000); + TimeStamp<3, 2> time4(defaultCUC2); CHECK(time4.asTAIseconds() == 100); - CHECK(time4.asCustomCUCTimestamp().elapsed100msTicks == 1004); + CHECK(DefaultCUC(time4).formatAsBytes() == 1004); // check rounding errors - Time::CustomCUC_t customCUC3 = {1005}; - TimeStamp<3, 0> time5(customCUC3); + Time::DefaultCUC defaultCUC3(1005_t); + TimeStamp<3, 0> time5(defaultCUC3); CHECK(time5.asTAIseconds() == 101); - CHECK(time5.asCustomCUCTimestamp().elapsed100msTicks == 1010); - TimeStamp<3, 2> time6(customCUC3); + CHECK(DefaultCUC(time5).formatAsBytes() == 1010); + TimeStamp<3, 2> time6(defaultCUC3); CHECK(time6.asTAIseconds() == 100); - CHECK(time6.asCustomCUCTimestamp().elapsed100msTicks == 1005); + CHECK(DefaultCUC(time6).formatAsBytes() == 1005); } SECTION("Check idempotence") { - Time::CustomCUC_t customCUC1 = {1000}; - TimeStamp<3, 3> time1(customCUC1); - Time::CustomCUC_t customCUC2 = time1.asCustomCUCTimestamp(); - CHECK(customCUC1.elapsed100msTicks == customCUC2.elapsed100msTicks); + Time::DefaultCUC defaultCUC1(1000_t); + TimeStamp<3, 3> time1(defaultCUC1); + Time::DefaultCUC defaultCUC2(time1); + CHECK(defaultCUC1 == defaultCUC2); } } @@ -184,7 +185,7 @@ TEST_CASE("UTC overflow tests") { } } -TEST_CASE("Time operators") { +TEST_CASE("Time comparison operators") { SECTION("Same type") { TimeStamp<1, 2> time1; TimeStamp<1, 2> time2; @@ -239,6 +240,31 @@ TEST_CASE("Time operators") { } } +TEST_CASE("Finding distance between times") { + using namespace std::literals; + + SECTION("Same type") { + TimeStamp<1, 2> time1(15); + TimeStamp<1, 2> time2(30); + + CHECK(time2 - time1 == 15s); + CHECK(time1 - time2 == -15s); + } + + SECTION("Different type") { + TimeStamp<1, 2> time1(15); + TimeStamp<2, 1> time2(30); + TimeStamp<1, 0, 1, 1000> time3(300ms); + TimeStamp<1, 2> time4(300ms); + TimeStamp<1, 3> time5(300ms); + + CHECK(time2 - time1 == 15s); + CHECK(time1 - time2 == -15s); + CHECK(time3 - time1 == -14700ms); + CHECK(time1 - time4 == time1 - time5); + } +} + TEST_CASE("Time runtime class size") { REQUIRE(sizeof(TimeStamp<CUCSecondsBytes, CUCFractionalBytes>) <= 8); }