Merge branch 'mueller/event-update' of https://egit.irs.uni-stuttgart.de/eive/fsfw into mueller/event-update

This commit is contained in:
2022-03-14 15:08:54 +01:00
23 changed files with 324 additions and 58 deletions

View File

@ -1,3 +1,7 @@
target_sources(${LIB_FSFW_NAME} PRIVATE
version.cpp
)
# Core
add_subdirectory(action)

View File

@ -2,8 +2,8 @@
#define FSFW_VERSION_H_
// Versioning is kept in project CMakeLists.txt file
#define FSFW_VERSION @FSFW_VERSION@
#define FSFW_SUBVERSION @FSFW_SUBVERSION@
#define FSFW_REVISION @FSFW_REVISION@
#define FSFW_VERSION_MAJOR @FSFW_VERSION@
#define FSFW_VERSION_MINOR @FSFW_SUBVERSION@
#define FSFW_VERSION_REVISION @FSFW_REVISION@
#endif /* FSFW_VERSION_H_ */

View File

@ -150,17 +150,14 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval*
time_tm.tm_hour = from->hour;
time_tm.tm_min = from->minute;
time_tm.tm_sec = from->second;
time_tm.tm_isdst = 0;
time_t seconds = mktime(&time_tm);
time_t seconds = timegm(&time_tm);
to->tv_sec = seconds;
to->tv_usec = from->usecond;
// Fails in 2038..
return HasReturnvaluesIF::RETURN_OK;
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "Clock::convertTimeBla: not implemented yet" << std::endl;
#endif
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t Clock::convertTimevalToJD2000(timeval time, double* JD2000) {

View File

@ -140,8 +140,9 @@ ReturnValue_t Clock::convertTimeOfDayToTimeval(const TimeOfDay_t* from, timeval*
fromTm.tm_hour = from->hour;
fromTm.tm_min = from->minute;
fromTm.tm_sec = from->second;
fromTm.tm_isdst = 0;
to->tv_sec = mktime(&fromTm);
to->tv_sec = timegm(&fromTm);
to->tv_usec = from->usecond;
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -557,6 +557,35 @@ ReturnValue_t CCSDSTime::convertFromCDS(timeval* to, const uint8_t* from, size_t
return RETURN_OK;
}
ReturnValue_t CCSDSTime::convertFromCDS(timeval* to, const CCSDSTime::CDS_short* from) {
if (to == nullptr or from == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
uint16_t days = (from->dayMSB << 8) + from->dayLSB;
if (days <= DAYS_CCSDS_TO_UNIX_EPOCH) {
return INVALID_TIME_FORMAT;
}
days -= DAYS_CCSDS_TO_UNIX_EPOCH;
to->tv_sec = days * SECONDS_PER_DAY;
uint32_t msDay =
(from->msDay_hh << 24) + (from->msDay_h << 16) + (from->msDay_l << 8) + from->msDay_ll;
to->tv_sec += (msDay / 1000);
to->tv_usec = (msDay % 1000) * 1000;
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CCSDSTime::convertFromCDS(Clock::TimeOfDay_t* to, const CCSDSTime::CDS_short* from) {
if (to == nullptr or from == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED;
}
timeval tempTimeval;
ReturnValue_t result = convertFromCDS(&tempTimeval, from);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
return CCSDSTime::convertTimevalToTimeOfDay(to, &tempTimeval);
}
ReturnValue_t CCSDSTime::convertFromCUC(timeval* to, uint8_t pField, const uint8_t* from,
size_t* foundLength, size_t maxLength) {
uint32_t secs = 0;

View File

@ -180,6 +180,8 @@ class CCSDSTime : public HasReturnvaluesIF {
static ReturnValue_t convertFromCDS(timeval *to, uint8_t const *from, size_t *foundLength,
size_t maxLength);
static ReturnValue_t convertFromCDS(timeval *to, const CCSDSTime::CDS_short *from);
static ReturnValue_t convertFromCDS(Clock::TimeOfDay_t *to, const CCSDSTime::CDS_short *from);
static ReturnValue_t convertFromCCS(Clock::TimeOfDay_t *to, uint8_t const *from,
size_t *foundLength, size_t maxLength);

View File

@ -1,6 +1,8 @@
#include "fsfw/timemanager/Countdown.h"
Countdown::Countdown(uint32_t initialTimeout) : timeout(initialTimeout) {}
Countdown::Countdown(uint32_t initialTimeout) : timeout(initialTimeout) {
setTimeout(initialTimeout);
}
Countdown::~Countdown() {}

22
src/fsfw/version.cpp Normal file
View File

@ -0,0 +1,22 @@
#include "version.h"
#include "fsfw/FSFWVersion.h"
#include <cstdio>
#ifdef major
#undef major
#endif
#ifdef minor
#undef minor
#endif
const fsfw::Version fsfw::FSFW_VERSION = {FSFW_VERSION_MAJOR, FSFW_VERSION_MINOR,
FSFW_VERSION_REVISION};
fsfw::Version::Version(uint32_t major, uint32_t minor, uint32_t revision)
: major(major), minor(minor), revision(revision) {}
void fsfw::Version::getVersion(char* str, size_t maxLen) const {
snprintf(str, maxLen, "%d.%d.%d", major, minor, revision);
}

64
src/fsfw/version.h Normal file
View File

@ -0,0 +1,64 @@
#ifndef FSFW_SRC_FSFW_VERSION_H_
#define FSFW_SRC_FSFW_VERSION_H_
#include "fsfw/FSFW.h"
#if FSFW_CPP_OSTREAM_ENABLED == 1
#include <iostream>
#endif
#include <cstdint>
namespace fsfw {
class Version {
public:
Version(uint32_t major, uint32_t minor, uint32_t revision);
uint32_t major = 0;
uint32_t minor = 0;
uint32_t revision = 0;
friend bool operator==(const Version& v1, const Version& v2) {
return (v1.major == v2.major and v1.minor == v2.minor and v1.revision == v2.revision);
}
friend bool operator!=(const Version& v1, const Version& v2) { return not(v1 == v2); }
friend bool operator<(const Version& v1, const Version& v2) {
return ((v1.major < v2.major) or (v1.major == v2.major and v1.minor < v2.minor) or
(v1.major == v2.major and v1.minor == v2.minor and v1.revision < v2.revision));
}
friend bool operator>(const Version& v1, const Version& v2) {
return not (v1 < v2) and not (v1 == v2);
}
friend bool operator<=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 < v2)); }
friend bool operator>=(const Version& v1, const Version& v2) { return ((v1 == v2) or (v1 > v2)); }
#if FSFW_CPP_OSTREAM_ENABLED == 1
/**
* Print format to given ostream using format "major.minor.revision"
* @param os
* @param v
* @return
*/
friend std::ostream& operator<<(std::ostream& os, const Version& v) {
os << v.major << "." << v.minor << "." << v.revision;
return os;
}
#endif
/**
* Get version as format "major.minor.revision"
* @param str
* @param maxLen
*/
void getVersion(char* str, size_t maxLen) const;
};
extern const fsfw::Version FSFW_VERSION;
} // namespace fsfw
#endif /* FSFW_SRC_FSFW_VERSION_H_ */