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 <cmath>
#include "fsfw/events/EventManagerIF.h"
#include "fsfw/pus/servicepackets/Service9Packets.h" #include "fsfw/pus/servicepackets/Service9Packets.h"
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/serialize/SerializeAdapter.h" #include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h" #include "fsfw/timemanager/CCSDSTime.h"
Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) { Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {
@ -19,7 +18,10 @@ ReturnValue_t Service9TimeManagement::performService() { return returnvalue::OK;
ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) { ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
switch (subservice) { switch (subservice) {
case Subservice::SET_TIME: { case Subservice::SET_TIME: {
return setTime(); reportCurrentTime();
ReturnValue_t result = setTime();
reportCurrentTime();
return result;
} }
case Subservice::DUMP_TIME: { case Subservice::DUMP_TIME: {
timeval newTime; timeval newTime;
@ -36,6 +38,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
return result; return result;
} }
triggerEvent(CLOCK_DUMP, currentTime.tv_sec, currentTime.tv_usec);
if (currentPacket.getUserDataLen() != 8) { if (currentPacket.getUserDataLen() != 8) {
return AcceptsTelecommandsIF::ILLEGAL_APPLICATION_DATA; return AcceptsTelecommandsIF::ILLEGAL_APPLICATION_DATA;
@ -63,8 +66,7 @@ ReturnValue_t Service9TimeManagement::handleRequest(uint8_t subservice) {
} }
result = Clock::setClock(&newTime); result = Clock::setClock(&newTime);
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
// Report new time as event. reportTime(newTime);
triggerEvent(CLOCK_DUMP, newTime.tv_sec, newTime.tv_usec);
} }
return result; return result;
} }
@ -83,17 +85,20 @@ ReturnValue_t Service9TimeManagement::setTime() {
return result; return result;
} }
timeval time;
Clock::getClock_timeval(&time);
result = Clock::setClock(&timeToSet); result = Clock::setClock(&timeToSet);
if (result != returnvalue::OK) {
if (result == returnvalue::OK) {
timeval newTime;
Clock::getClock_timeval(&newTime);
triggerEvent(CLOCK_SET, time.tv_sec, newTime.tv_sec);
return returnvalue::OK;
} else {
triggerEvent(CLOCK_SET_FAILURE, result, 0); triggerEvent(CLOCK_SET_FAILURE, result, 0);
return returnvalue::FAILED; 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,13 +1,14 @@
#ifndef FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_ #ifndef FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_
#define FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_ #define FSFW_PUS_SERVICE9TIMEMANAGEMENT_H_
#include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/tmtcservices/PusServiceBase.h" #include "fsfw/tmtcservices/PusServiceBase.h"
class Service9TimeManagement : public PusServiceBase { class Service9TimeManagement : public PusServiceBase {
public: public:
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_9; static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_9;
static constexpr uint32_t NANOS_PER_SECOND= 1'000'000'000; static constexpr uint32_t NANOS_PER_SECOND = 1'000'000'000;
//!< Clock has been set. P1: old timeval seconds. P2: new timeval seconds. //!< Clock has been set. P1: old timeval seconds. P2: new timeval seconds.
static constexpr Event CLOCK_SET = MAKE_EVENT(0, severity::INFO); static constexpr Event CLOCK_SET = MAKE_EVENT(0, severity::INFO);
@ -32,6 +33,9 @@ class Service9TimeManagement : public PusServiceBase {
*/ */
ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t handleRequest(uint8_t subservice) override;
void reportCurrentTime();
void reportTime(timeval time);
virtual ReturnValue_t setTime(); virtual ReturnValue_t setTime();
private: private: