diff --git a/inc/Services/ParameterStatisticsService.hpp b/inc/Services/ParameterStatisticsService.hpp index d04a12afa22932ba01b887b182bfbc7cd3fc36a5..1b44bc759b4823c6a726b77a552cf1c3558a7aa9 100644 --- a/inc/Services/ParameterStatisticsService.hpp +++ b/inc/Services/ParameterStatisticsService.hpp @@ -158,6 +158,16 @@ public: * @param message Contains the necessary parameters to call the suitable subservice */ void execute(Message& message); + + /** + * BaseBytes: 4 bytes, FractionBytes: 0 bytes, Num: 1, Denom: 10. + */ + using DefaultTimestamp = TimeStamp<4, 0, 1, 10>; + + /** + * Get the current time as a TimeStamp object. + */ + DefaultTimestamp getCurrentTime(); }; #endif diff --git a/src/Services/ParameterStatisticsService.cpp b/src/Services/ParameterStatisticsService.cpp index 6bcfc9b489bc5195bec737dfbbd86fc413d2b42a..6892124e556f73d2bb9057bb9cf573967fd4b385 100644 --- a/src/Services/ParameterStatisticsService.cpp +++ b/src/Services/ParameterStatisticsService.cpp @@ -71,21 +71,19 @@ void ParameterStatisticsService::resetParameterStatistics() { } void ParameterStatisticsService::enablePeriodicStatisticsReporting(Message& request) { - /** - * @todo: The sampling interval of each parameter. the "timeInterval" requested should not exceed it. - * It has to be defined as a constant. - */ - uint16_t SAMPLING_PARAMETER_INTERVAL = 5; + Time::RelativeTime constexpr SamplingParameterInterval = 5; if (!request.assertTC(ServiceType, MessageType::EnablePeriodicParameterReporting)) { return; } uint16_t timeInterval = request.readUint16(); - if (timeInterval < SAMPLING_PARAMETER_INTERVAL) { + + if (timeInterval < SamplingParameterInterval) { ErrorHandler::reportError(request, ErrorHandler::ExecutionStartErrorType::InvalidSamplingRateError); return; } + periodicStatisticsReportingStatus = true; reportingIntervalMs = timeInterval; } @@ -197,14 +195,17 @@ void ParameterStatisticsService::statisticsDefinitionsReport() { } void ParameterStatisticsService::execute(Message& message) { + DefaultTimestamp currentTime; switch (message.messageType) { case ReportParameterStatistics: reportParameterStatistics(message); break; case ResetParameterStatistics: resetParameterStatistics(message); + currentTime = getCurrentTime(); break; case EnablePeriodicParameterReporting: + currentTime = getCurrentTime(); enablePeriodicStatisticsReporting(message); break; case DisablePeriodicParameterReporting: @@ -217,6 +218,7 @@ void ParameterStatisticsService::execute(Message& message) { deleteStatisticsDefinitions(message); break; case ReportParameterStatisticsDefinitions: + currentTime = getCurrentTime(); reportStatisticsDefinitions(message); break; default: @@ -224,4 +226,8 @@ void ParameterStatisticsService::execute(Message& message) { } } +ParameterStatisticsService::DefaultTimestamp ParameterStatisticsService::getCurrentTime() { + return TimeGetter::getCurrentTimeDefaultCUC(); +} + #endif