some optimizations

This commit is contained in:
Robin Müller 2024-04-08 13:14:20 +02:00
parent aff6bb673b
commit 31d4b85523
2 changed files with 24 additions and 15 deletions

View File

@ -2,10 +2,9 @@
#include <cmath>
#include "fsfw/events/EventManagerIF.h"
#include "fsfw/pus/servicepackets/Service9Packets.h"
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h"
Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {
@ -19,7 +18,10 @@ ReturnValue_t Service9TimeManagement::performService() { return returnvalue::OK;
ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
switch (subservice) {
case Subservice::SET_TIME: {
return setTime();
reportCurrentTime();
ReturnValue_t result = setTime();
reportCurrentTime();
return result;
}
case Subservice::DUMP_TIME: {
timeval newTime;
@ -36,6 +38,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
if (result != returnvalue::OK) {
return result;
}
triggerEvent(CLOCK_DUMP, currentTime.tv_sec, currentTime.tv_usec);
if (currentPacket.getUserDataLen() != 8) {
return AcceptsTelecommandsIF::ILLEGAL_APPLICATION_DATA;
@ -63,8 +66,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
}
result = Clock::setClock(&newTime);
if (result == returnvalue::OK) {
// Report new time as event.
triggerEvent(CLOCK_DUMP, newTime.tv_sec, newTime.tv_usec);
reportTime(newTime);
}
return result;
}
@ -83,17 +85,20 @@ ReturnValue_t Service9TimeManagement::setTime() {
return result;
}
timeval time;
Clock::getClock_timeval(&time);
result = Clock::setClock(&timeToSet);
if (result == returnvalue::OK) {
timeval newTime;
Clock::getClock_timeval(&newTime);
triggerEvent(CLOCK_SET, time.tv_sec, newTime.tv_sec);
return returnvalue::OK;
} else {
if (result != returnvalue::OK) {
triggerEvent(CLOCK_SET_FAILURE, result, 0);
return returnvalue::FAILED;
}
return result;
}
void Service9TimeManagement::reportCurrentTime() {
timeval currentTime{};
Clock::getClock_timeval(&currentTime);
triggerEvent(CLOCK_DUMP, currentTime.tv_sec, currentTime.tv_usec);
}
void Service9TimeManagement::reportTime(timeval time) {
triggerEvent(CLOCK_DUMP, time.tv_sec, time.tv_usec);
}

View File

@ -1,6 +1,7 @@
#ifndef FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_
#define FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/tmtcservices/PusServiceBase.h"
class Service9TimeManagement : public PusServiceBase {
@ -32,6 +33,9 @@ class Service9TimeManagement : public PusServiceBase {
*/
ReturnValue_t handleRequest(uint8_t subservice) override;
void reportCurrentTime();
void reportTime(timeval time);
virtual ReturnValue_t setTime();
private: