Merge pull request 'CCSDS Time CUC Tests' (#593) from gaisser/fsfw:gaisser_cuc_tests into development
Reviewed-on: fsfw/fsfw#593
This commit is contained in:
commit
1a07864a5f
@ -6,10 +6,6 @@
|
||||
|
||||
#include "fsfw/FSFW.h"
|
||||
|
||||
CCSDSTime::CCSDSTime() {}
|
||||
|
||||
CCSDSTime::~CCSDSTime() {}
|
||||
|
||||
ReturnValue_t CCSDSTime::convertToCcsds(Ccs_seconds* to, const Clock::TimeOfDay_t* from) {
|
||||
ReturnValue_t result = checkTimeOfDay(from);
|
||||
if (result != RETURN_OK) {
|
||||
@ -428,7 +424,7 @@ ReturnValue_t CCSDSTime::convertFromCUC(timeval* to, const uint8_t* from, size_t
|
||||
from++;
|
||||
ReturnValue_t result = convertFromCUC(to, pField, from, foundLength, maxLength - 1);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
if (foundLength != NULL) {
|
||||
if (foundLength != nullptr) {
|
||||
*foundLength += 1;
|
||||
}
|
||||
}
|
||||
@ -588,18 +584,18 @@ ReturnValue_t CCSDSTime::convertFromCUC(timeval* to, uint8_t pField, const uint8
|
||||
uint8_t nCoarse = ((pField & 0b1100) >> 2) + 1;
|
||||
uint8_t nFine = (pField & 0b11);
|
||||
size_t totalLength = nCoarse + nFine;
|
||||
if (foundLength != NULL) {
|
||||
if (foundLength != nullptr) {
|
||||
*foundLength = totalLength;
|
||||
}
|
||||
if (totalLength > maxLength) {
|
||||
return LENGTH_MISMATCH;
|
||||
}
|
||||
for (int count = 0; count < nCoarse; count++) {
|
||||
secs += *from << ((nCoarse * 8 - 8) * (1 + count));
|
||||
for (int count = nCoarse; count > 0; count--) {
|
||||
secs += *from << (count * 8 - 8);
|
||||
from++;
|
||||
}
|
||||
for (int count = 0; count < nFine; count++) {
|
||||
subSeconds += *from << ((nFine * 8 - 8) * (1 + count));
|
||||
for (int count = nFine; count > 0; count--) {
|
||||
subSeconds += *from << (count * 8 - 8);
|
||||
from++;
|
||||
}
|
||||
// Move to POSIX epoch.
|
||||
|
@ -161,18 +161,37 @@ class CCSDSTime : public HasReturnvaluesIF {
|
||||
*/
|
||||
static ReturnValue_t convertFromCcsds(timeval *to, uint8_t const *from, size_t *foundLength,
|
||||
size_t maxLength);
|
||||
|
||||
/**
|
||||
* @brief Currently unsupported conversion due to leapseconds
|
||||
*
|
||||
* @param to Time Of Day (UTC)
|
||||
* @param from Buffer to take the CUC from
|
||||
* @param length Length of buffer
|
||||
* @return ReturnValue_t UNSUPPORTED_TIME_FORMAT in any case ATM
|
||||
*/
|
||||
static ReturnValue_t convertFromCUC(Clock::TimeOfDay_t *to, uint8_t const *from, uint8_t length);
|
||||
|
||||
/**
|
||||
* @brief Converts from CCSDS CUC to timeval
|
||||
*
|
||||
* If input is CCSDS Epoch this is TAI! -> No leapsecond support.
|
||||
*
|
||||
* Currently, it only supports seconds + 2 Byte Subseconds (1/65536 seconds)
|
||||
*
|
||||
*
|
||||
* @param to Timeval to write the result to
|
||||
* @param from Buffer to read from
|
||||
* @param foundLength Length found by this function (can be nullptr if unused)
|
||||
* @param maxLength Max length of the buffer to be read
|
||||
* @return ReturnValue_t - RETURN_OK if successful
|
||||
* - LENGTH_MISMATCH if expected length is larger than maxLength
|
||||
*/
|
||||
static ReturnValue_t convertFromCUC(timeval *to, uint8_t const *from, size_t *foundLength,
|
||||
size_t maxLength);
|
||||
|
||||
static ReturnValue_t convertFromCUC(timeval *to, uint8_t pField, uint8_t const *from,
|
||||
size_t *foundLength, size_t maxLength);
|
||||
|
||||
static ReturnValue_t convertFromCCS(timeval *to, uint8_t const *from, size_t *foundLength,
|
||||
size_t maxLength);
|
||||
|
||||
static ReturnValue_t convertFromCCS(timeval *to, uint8_t pField, uint8_t const *from,
|
||||
size_t *foundLength, size_t maxLength);
|
||||
|
||||
@ -192,8 +211,8 @@ class CCSDSTime : public HasReturnvaluesIF {
|
||||
static uint32_t subsecondsToMicroseconds(uint16_t subseconds);
|
||||
|
||||
private:
|
||||
CCSDSTime();
|
||||
virtual ~CCSDSTime();
|
||||
CCSDSTime(){};
|
||||
virtual ~CCSDSTime(){};
|
||||
/**
|
||||
* checks a ccs time stream for validity
|
||||
*
|
||||
|
@ -179,6 +179,27 @@ TEST_CASE("CCSDSTime Tests", "[TestCCSDSTime]") {
|
||||
CHECK(todFromCCSDS.second == time.second);
|
||||
CHECK(todFromCCSDS.usecond == 123000);
|
||||
}
|
||||
SECTION("CUC") {
|
||||
timeval to;
|
||||
// seconds = 0x771E960F, microseconds = 0x237
|
||||
// microseconds = 567000
|
||||
// This gives 37158.912 1/65536 seconds -> rounded to 37159 -> 0x9127
|
||||
// This results in -> 567001 us
|
||||
std::array<uint8_t, 7> cucBuffer = {
|
||||
CCSDSTime::P_FIELD_CUC_6B_CCSDS, 0x77, 0x1E, 0x96, 0x0F, 0x91, 0x27};
|
||||
size_t foundLength = 0;
|
||||
auto result = CCSDSTime::convertFromCUC(&to, cucBuffer.data(), &foundLength, cucBuffer.size());
|
||||
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(foundLength == 7);
|
||||
REQUIRE(to.tv_sec == 1619801999); // TAI (no leap seconds)
|
||||
REQUIRE(to.tv_usec == 567001);
|
||||
|
||||
Clock::TimeOfDay_t tod;
|
||||
result = CCSDSTime::convertFromCUC(&tod, cucBuffer.data(), cucBuffer.size());
|
||||
// This test must be changed if this is ever going to be implemented
|
||||
REQUIRE(result == CCSDSTime::UNSUPPORTED_TIME_FORMAT);
|
||||
}
|
||||
|
||||
SECTION("CCSDS Failures") {
|
||||
Clock::TimeOfDay_t time;
|
||||
time.year = 2020;
|
||||
|
Loading…
Reference in New Issue
Block a user