taken over changes from master

This commit is contained in:
Robin Müller 2020-11-03 16:46:43 +01:00
parent f69f9bb31e
commit 9e97357b8c
8 changed files with 109 additions and 55 deletions

View File

@ -12,7 +12,7 @@ CCSDSTime::~CCSDSTime() {
}
ReturnValue_t CCSDSTime::convertToCcsds(Ccs_seconds* to,
const TimeOfDay_t* from) {
const Clock::TimeOfDay_t* from) {
ReturnValue_t result = checkTimeOfDay(from);
if (result != RETURN_OK) {
return result;
@ -32,7 +32,7 @@ ReturnValue_t CCSDSTime::convertToCcsds(Ccs_seconds* to,
}
ReturnValue_t CCSDSTime::convertToCcsds(Ccs_mseconds* to,
const TimeOfDay_t* from) {
const Clock::TimeOfDay_t* from) {
ReturnValue_t result = checkTimeOfDay(from);
if (result != RETURN_OK) {
return result;
@ -53,8 +53,8 @@ ReturnValue_t CCSDSTime::convertToCcsds(Ccs_mseconds* to,
return RETURN_OK;
}
ReturnValue_t CCSDSTime::convertFromCcsds(TimeOfDay_t* to, const uint8_t* from,
uint32_t length) {
ReturnValue_t CCSDSTime::convertFromCcsds(Clock::TimeOfDay_t* to,
const uint8_t* from, uint32_t length) {
ReturnValue_t result;
if (length > 0xFF) {
return LENGTH_MISMATCH;
@ -81,13 +81,13 @@ ReturnValue_t CCSDSTime::convertFromCcsds(TimeOfDay_t* to, const uint8_t* from,
}
}
ReturnValue_t CCSDSTime::convertFromCUC(TimeOfDay_t* to, const uint8_t* from,
uint8_t length) {
ReturnValue_t CCSDSTime::convertFromCUC(Clock::TimeOfDay_t* to,
const uint8_t* from, uint8_t length) {
return UNSUPPORTED_TIME_FORMAT;
}
ReturnValue_t CCSDSTime::convertFromCDS(TimeOfDay_t* to, const uint8_t* from,
uint8_t length) {
ReturnValue_t CCSDSTime::convertFromCDS(Clock::TimeOfDay_t* to,
const uint8_t* from, uint8_t length) {
timeval time;
ReturnValue_t result = convertFromCDS(&time, from, NULL, length);
if (result != HasReturnvaluesIF::RETURN_OK) {
@ -96,8 +96,8 @@ ReturnValue_t CCSDSTime::convertFromCDS(TimeOfDay_t* to, const uint8_t* from,
return convertTimevalToTimeOfDay(to, &time);
}
ReturnValue_t CCSDSTime::convertFromCCS(TimeOfDay_t* to, const uint8_t* from,
uint32_t* foundLength, uint32_t maxLength) {
ReturnValue_t CCSDSTime::convertFromCCS(Clock::TimeOfDay_t* to,
const uint8_t* from, uint32_t* foundLength, uint32_t maxLength) {
uint8_t subsecondsLength = *from & 0b111;
uint32_t totalLength = subsecondsLength + 8;
if (maxLength < totalLength) {
@ -152,8 +152,8 @@ ReturnValue_t CCSDSTime::convertFromCCS(TimeOfDay_t* to, const uint8_t* from,
}
ReturnValue_t CCSDSTime::convertFromASCII(TimeOfDay_t* to, const uint8_t* from,
uint8_t length) {
ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to,
const uint8_t* from, uint8_t length) {
if (length < 19) {
return RETURN_FAILED;
}
@ -166,8 +166,9 @@ ReturnValue_t CCSDSTime::convertFromASCII(TimeOfDay_t* to, const uint8_t* from,
uint16_t hour;
uint16_t minute;
float second;
int count = sscanf((char *) from, "%4" SCNu16 "-%2" SCNu16 "-%2" SCNu16 "T%2" SCNu16 ":%2" SCNu16 ":%fZ", &year,
&month, &day, &hour, &minute, &second);
int count = sscanf((char *) from, "%4" SCNu16 "-%2" SCNu16 "-%2" SCNu16 "T%"
"2" SCNu16 ":%2" SCNu16 ":%fZ", &year, &month, &day, &hour,
&minute, &second);
if (count == 6) {
to->year = year;
to->month = month;
@ -180,12 +181,13 @@ ReturnValue_t CCSDSTime::convertFromASCII(TimeOfDay_t* to, const uint8_t* from,
}
// try Code B (yyyy-ddd)
count = sscanf((char *) from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu16 ":%2" SCNu16 ":%fZ", &year, &day,
&hour, &minute, &second);
count = sscanf((char *) from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu16 ":%"
"2" SCNu16 ":%fZ", &year, &day, &hour, &minute, &second);
if (count == 5) {
uint8_t tempDay;
ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year,
reinterpret_cast<uint8_t *>(&month), reinterpret_cast<uint8_t *>(&tempDay));
reinterpret_cast<uint8_t *>(&month),
reinterpret_cast<uint8_t *>(&tempDay));
if (result != RETURN_OK) {
return RETURN_FAILED;
}
@ -427,7 +429,7 @@ ReturnValue_t CCSDSTime::convertFromCUC(timeval* to, const uint8_t* from,
return result;
}
ReturnValue_t CCSDSTime::checkTimeOfDay(const TimeOfDay_t* time) {
ReturnValue_t CCSDSTime::checkTimeOfDay(const Clock::TimeOfDay_t* time) {
if ((time->month > 12) || (time->month == 0)) {
return INVALID_TIME_FORMAT;
}
@ -482,7 +484,7 @@ ReturnValue_t CCSDSTime::checkTimeOfDay(const TimeOfDay_t* time) {
}
ReturnValue_t CCSDSTime::convertTimevalToTimeOfDay(TimeOfDay_t* to,
ReturnValue_t CCSDSTime::convertTimevalToTimeOfDay(Clock::TimeOfDay_t* to,
timeval* from) {
//This is rather tricky. Implement only if needed. Also, if so, move to OSAL.
return UNSUPPORTED_TIME_FORMAT;
@ -592,7 +594,7 @@ uint32_t CCSDSTime::subsecondsToMicroseconds(uint16_t subseconds) {
ReturnValue_t CCSDSTime::convertFromCCS(timeval* to, const uint8_t* from,
uint32_t* foundLength, uint32_t maxLength) {
TimeOfDay_t tempTime;
Clock::TimeOfDay_t tempTime;
ReturnValue_t result = convertFromCCS(&tempTime, from, foundLength,
maxLength);
if (result != RETURN_OK) {

View File

@ -112,7 +112,7 @@ public:
* - @c INVALID_TIMECODE if not OK
*/
static ReturnValue_t convertToCcsds(Ccs_seconds *to,
TimeOfDay_t const *from);
Clock::TimeOfDay_t const *from);
/**
* Converts to CDS format from timeval.
@ -137,7 +137,7 @@ public:
* - @c INVALID_TIMECODE if not OK
*/
static ReturnValue_t convertToCcsds(Ccs_mseconds *to,
TimeOfDay_t const *from);
Clock::TimeOfDay_t const *from);
/**
* SHOULDDO: can this be modified to recognize padding?
@ -155,8 +155,8 @@ public:
* - @c LENGTH_MISMATCH if the length does not match the P Field
* - @c INVALID_TIME_FORMAT if the format or a value is invalid
*/
static ReturnValue_t convertFromCcsds(TimeOfDay_t *to, uint8_t const *from,
uint32_t length);
static ReturnValue_t convertFromCcsds(Clock::TimeOfDay_t *to,
uint8_t const *from, uint32_t length);
/**
* not implemented yet
@ -168,8 +168,8 @@ public:
static ReturnValue_t convertFromCcsds(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCUC(TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromCUC(Clock::TimeOfDay_t *to,
uint8_t const *from, uint8_t length);
static ReturnValue_t convertFromCUC(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
@ -183,17 +183,17 @@ public:
static ReturnValue_t convertFromCCS(timeval *to, uint8_t pField,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCDS(TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromCDS(Clock::TimeOfDay_t *to,
uint8_t const *from, uint8_t length);
static ReturnValue_t convertFromCDS(timeval *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(TimeOfDay_t *to, uint8_t const *from,
uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromCCS(Clock::TimeOfDay_t *to,
uint8_t const *from, uint32_t* foundLength, uint32_t maxLength);
static ReturnValue_t convertFromASCII(TimeOfDay_t *to, uint8_t const *from,
uint8_t length);
static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to,
uint8_t const *from, uint8_t length);
static uint32_t subsecondsToMicroseconds(uint16_t subseconds);
private:
@ -210,7 +210,7 @@ private:
*/
static ReturnValue_t checkCcs(const uint8_t* time, uint8_t length);
static ReturnValue_t checkTimeOfDay(const TimeOfDay_t *time);
static ReturnValue_t checkTimeOfDay(const Clock::TimeOfDay_t *time);
static const uint32_t SECONDS_PER_DAY = 24 * 60 * 60;
static const uint32_t SECONDS_PER_NON_LEAP_YEAR = SECONDS_PER_DAY * 365;
@ -227,7 +227,7 @@ private:
uint8_t *month, uint8_t *day);
static bool isLeapYear(uint32_t year);
static ReturnValue_t convertTimevalToTimeOfDay(TimeOfDay_t* to,
static ReturnValue_t convertTimevalToTimeOfDay(Clock::TimeOfDay_t* to,
timeval* from);
};

View File

@ -11,6 +11,15 @@
class Clock {
public:
typedef struct {
uint32_t year; //!< Year, A.D.
uint32_t month; //!< Month, 1 .. 12.
uint32_t day; //!< Day, 1 .. 31.
uint32_t hour; //!< Hour, 0 .. 23.
uint32_t minute; //!< Minute, 0 .. 59.
uint32_t second; //!< Second, 0 .. 59.
uint32_t usecond; //!< Microseconds, 0 .. 999999
} TimeOfDay_t;
/**
* This method returns the number of clock ticks per second.
@ -56,8 +65,6 @@ public:
static timeval getUptime();
static uint32_t getUptimeSeconds();
/**
* Get the time since boot in milliseconds
*

View File

@ -1,4 +1,4 @@
#include "../timemanager/Stopwatch.h"
#include "Stopwatch.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <iomanip>

View File

@ -1,11 +1,4 @@
/**
* @file TimeMessage.cpp
* @brief This file defines the TimeMessage class.
* @date 26.02.2013
* @author baetz
*/
#include "../timemanager/TimeMessage.h"
#include "TimeMessage.h"
TimeMessage::TimeMessage() {
this->messageSize += sizeof(timeval) + sizeof(uint32_t);

View File

@ -0,0 +1,23 @@
#include "TimeStamper.h"
#include "Clock.h"
#include <cstring>
TimeStamper::TimeStamper(object_id_t objectId): SystemObject(objectId) {}
ReturnValue_t TimeStamper::addTimeStamp(uint8_t* buffer,
const uint8_t maxSize) {
if(maxSize < TimeStamperIF::MISSION_TIMESTAMP_SIZE){
return HasReturnvaluesIF::RETURN_FAILED;
}
timeval now;
Clock::getClock_timeval(&now);
CCSDSTime::CDS_short cds;
ReturnValue_t result = CCSDSTime::convertToCcsds(&cds,&now);
if(result != HasReturnvaluesIF::RETURN_OK){
return result;
}
std::memcpy(buffer,&cds,sizeof(cds));
return result;
}

36
timemanager/TimeStamper.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef FSFW_TIMEMANAGER_TIMESTAMPER_H_
#define FSFW_TIMEMANAGER_TIMESTAMPER_H_
#include "TimeStamperIF.h"
#include "CCSDSTime.h"
#include "../objectmanager/SystemObject.h"
/**
* @brief Time stamper which can be used to add any timestamp to a
* given buffer.
* @details
* This time stamper uses the CCSDS CDC short timestamp as a fault timestamp.
* This timestamp has a size of 8 bytes. A custom timestamp can be used by
* overriding the #addTimeStamp function.
* @ingroup utility
*/
class TimeStamper: public TimeStamperIF, public SystemObject {
public:
/**
* @brief Default constructor which also registers the time stamper as a
* system object so it can be found with the #objectManager.
* @param objectId
*/
TimeStamper(object_id_t objectId);
/**
* Adds a CCSDS CDC short 8 byte timestamp to the given buffer.
* This function can be overriden to use a custom timestamp.
* @param buffer
* @param maxSize
* @return
*/
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize);
};
#endif /* FSFW_TIMEMANAGER_TIMESTAMPER_H_ */

View File

@ -3,16 +3,9 @@
#include <cstdint>
typedef struct {
uint32_t year; //!< Year, A.D.
uint32_t month; //!< Month, 1 .. 12.
uint32_t day; //!< Day, 1 .. 31.
uint32_t hour; //!< Hour, 0 .. 23.
uint32_t minute; //!< Minute, 0 .. 59.
uint32_t second; //!< Second, 0 .. 59.
uint32_t usecond; //!< Microseconds, 0 .. 999999
} TimeOfDay_t;
// I'd also like to include the TimeOfDay_t struct here, but that would
// break code which uses Clock::TimeOfDay_t. Solution would be to use
// a Clock namespace instead of class with static functions.
//! Don't use these for time points, type is not large enough for UNIX epoch.
using dur_millis_t = uint32_t;