implement relative timeshift #173

Merged
muellerr merged 10 commits from time-service-relative-timeshift into develop 2024-04-09 13:31:13 +02:00
3 changed files with 75 additions and 21 deletions

View File

@ -28,9 +28,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- add CFDP subsystem ID - add CFDP subsystem ID
https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/742 https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/742
- `PusTmZcWriter` now exposes API to set message counter field. - `PusTmZcWriter` now exposes API to set message counter field.
- Relative timeshift in the PUS time service.
## Changed ## Changed
- The PUS time service now dumps the time before setting a new time and after having set the
time.
- HK generation is now countdown based. - HK generation is now countdown based.
- Bump ETL version to 20.35.14 - Bump ETL version to 20.35.14
https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/748 https://egit.irs.uni-stuttgart.de/fsfw/fsfw/pulls/748

View File

@ -2,9 +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/serviceinterface/ServiceInterface.h" #include "fsfw/returnvalues/returnvalue.h"
#include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/timemanager/CCSDSTime.h" #include "fsfw/timemanager/CCSDSTime.h"
Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) { Service9TimeManagement::Service9TimeManagement(PsbParams params) : PusServiceBase(params) {
@ -18,16 +18,53 @@ 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(CLOCK_DUMP_BEFORE_SETTING_TIME);
ReturnValue_t result = setTime();
reportCurrentTime(CLOCK_DUMP_AFTER_SETTING_TIME);

if we are doing this twice, why did we not use the CLOCK_SET event then? it already contained old and new time. or are we really interessted in microseconds here?

if we are doing this twice, why did we not use the CLOCK_SET event then? it already contained old and new time. or are we really interessted in microseconds here?

events are cheap, and why lose resolution here? The correct approach probably would be to delete the weird CLOCK_SET event. If we still want to distinguish events which come from time changes, we could introduce, TIME_DUMP_BEFORE_CLOCK_UPDATE and TIME_DUMP_AFTER_CLOCK_UPDATE..

events are cheap, and why lose resolution here? The correct approach probably would be to delete the weird `CLOCK_SET` event. If we still want to distinguish events which come from time changes, we could introduce, `TIME_DUMP_BEFORE_CLOCK_UPDATE` and `TIME_DUMP_AFTER_CLOCK_UPDATE`..

I would advise splitting the events in those two types yes. Otherwise, this might be confusing for the operator. Calculating the time delta on ground is going to be more tricky now (but still possible if we store the parameter tm as actual tm). Maybe ask OPS what they prefer here

I would advise splitting the events in those two types yes. Otherwise, this might be confusing for the operator. Calculating the time delta on ground is going to be more tricky now (but still possible if we store the parameter tm as actual tm). Maybe ask OPS what they prefer here

done

done
return result;
} }
case Subservice::DUMP_TIME: { case Subservice::DUMP_TIME: {
timeval newTime; reportCurrentTime();
Clock::getClock_timeval(&newTime);
uint32_t subsecondMs =
static_cast<uint32_t>(std::floor(static_cast<double>(newTime.tv_usec) / 1000.0));
triggerEvent(CLOCK_DUMP, newTime.tv_sec, subsecondMs);
return returnvalue::OK; return returnvalue::OK;
} }
case Subservice::RELATIVE_TIMESHIFT: {
muellerr marked this conversation as resolved Outdated

either still dump milliseconds for P2 or change the description of the event

either still dump milliseconds for P2 or change the description of the event
timeval currentTime;
ReturnValue_t result = Clock::getClock(&currentTime);
if (result != returnvalue::OK) {
return result;
}
reportTime(CLOCK_DUMP_BEFORE_SETTING_TIME, currentTime);
if (currentPacket.getUserDataLen() != 8) {
return AcceptsTelecommandsIF::ILLEGAL_APPLICATION_DATA;
}
size_t deserLen = 8;
int64_t timeshiftNanos = 0;
result = SerializeAdapter::deSerialize(&timeshiftNanos, currentPacket.getUserData(),
&deserLen, SerializeIF::Endianness::NETWORK);
if (result != returnvalue::OK) {
return result;
}
bool positiveShift = true;
if (timeshiftNanos < 0) {
positiveShift = false;
}
timeval offset{};
offset.tv_sec = std::abs(timeshiftNanos) / NANOS_PER_SECOND;
offset.tv_usec = (std::abs(timeshiftNanos) % NANOS_PER_SECOND) / 1000;
muellerr marked this conversation as resolved Outdated

my man refusing to use 1e-9 so that one has to count the 0 individually

my man refusing to use 1e-9 so that one has to count the 0 individually

Isn't that a float/double implicitely? WE are using C++17 anyway, we can just use 1'000'000'000 I guess

Isn't that a float/double implicitely? WE are using C++17 anyway, we can just use 1'000'000'000 I guess

1e9 is what i meant

1e9 is what i meant
timeval newTime;
if (positiveShift) {
newTime = currentTime + offset;
} else {
newTime = currentTime - offset;
}
result = Clock::setClock(&newTime);
if (result == returnvalue::OK) {
reportTime(CLOCK_DUMP_AFTER_SETTING_TIME, newTime);
}
return result;
}
muellerr marked this conversation as resolved Outdated

see above

see above
default: default:
return AcceptsTelecommandsIF::INVALID_SUBSERVICE; return AcceptsTelecommandsIF::INVALID_SUBSERVICE;

the same here

the same here
} }
@ -43,17 +80,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(Event event) {
timeval currentTime{};
Clock::getClock(&currentTime);
triggerEvent(event, currentTime.tv_sec, currentTime.tv_usec);
}
void Service9TimeManagement::reportTime(Event event, timeval time) {
triggerEvent(event, time.tv_sec, time.tv_usec);
} }

View File

@ -1,18 +1,25 @@
#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;
//!< Clock has been set. P1: old timeval seconds. P2: new timeval seconds. static constexpr uint32_t NANOS_PER_SECOND = 1'000'000'000;
//!< [EXPORT] : [COMMENT] 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);
//!< Clock dump event. P1: timeval seconds P2: timeval milliseconds. //!< [EXPORT] : [COMMENT] Clock dump event. P1: timeval seconds P2: timeval milliseconds.
static constexpr Event CLOCK_DUMP = MAKE_EVENT(1, severity::INFO); static constexpr Event CLOCK_DUMP_LEGACY = MAKE_EVENT(1, severity::INFO);
//!< Clock could not be set. P1: Returncode. //!< [EXPORT] : [COMMENT] Clock could not be set. P1: Returncode.
static constexpr Event CLOCK_SET_FAILURE = MAKE_EVENT(2, severity::LOW); static constexpr Event CLOCK_SET_FAILURE = MAKE_EVENT(2, severity::LOW);
//!< [EXPORT] : [COMMENT] Clock dump event. P1: timeval seconds P2: timeval microseconds.
static constexpr Event CLOCK_DUMP = MAKE_EVENT(3, severity::INFO);
static constexpr Event CLOCK_DUMP_BEFORE_SETTING_TIME = MAKE_EVENT(4, severity::INFO);
static constexpr Event CLOCK_DUMP_AFTER_SETTING_TIME = MAKE_EVENT(5, severity::INFO);
static constexpr uint8_t CLASS_ID = CLASS_ID::PUS_SERVICE_9; static constexpr uint8_t CLASS_ID = CLASS_ID::PUS_SERVICE_9;
@ -30,12 +37,16 @@ class Service9TimeManagement : public PusServiceBase {
*/ */
ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t handleRequest(uint8_t subservice) override;
void reportCurrentTime(Event eventType = CLOCK_DUMP);
void reportTime(Event event, timeval time);
virtual ReturnValue_t setTime(); virtual ReturnValue_t setTime();
private: private:
enum Subservice { enum Subservice {
SET_TIME = 128, //!< [EXPORT] : [COMMAND] Time command in ASCII, CUC or CDS format SET_TIME = 128, //!< [EXPORT] : [COMMAND] Time command in ASCII, CUC or CDS format
DUMP_TIME = 129, DUMP_TIME = 129,
RELATIVE_TIMESHIFT = 130,
}; };
}; };