Skip to content
Snippets Groups Projects
Commit 2e1df331 authored by thodkatz's avatar thodkatz
Browse files

Minor changes

parent 67456dd6
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,8 @@ struct TimeAndDate {
*
* Note:
* Since this code is UTC-based, the leap second correction must be made. The leap seconds that
* have been occured between timestamps should be considered if a critical time-difference is needed
* have been occurred between timestamps should be considered if a critical time-difference is
* needed
*
*/
class TimeHelper {
......@@ -54,10 +55,10 @@ private:
* @return the elapsed seconds between a given UTC date(after the Unix epoch) and Unix epoch
* @todo change the epoch for computer-efficiency
*/
uint32_t mkUTCtime(struct TimeAndDate &timeInfo);
uint32_t mkUTCtime(struct TimeAndDate &TimeInfo);
/**
* Convert elapsed seconds since Unix epoxh to UTC date. This is a reimplemented gmtime() of
* Convert elapsed seconds since Unix epoch to UTC date. This is a reimplemented gmtime() of
* <ctime> library in an embedded systems way
*
* @param seconds elapsed seconds since Unix epoch
......@@ -88,13 +89,14 @@ public:
/**
* Parse the CDS time format(3.3 in CCSDS 301.0-B-4 standard)
*
* @param seconds elapsed seconds since Unix epoch
* @return the UTC date based on the /p
*/
static struct TimeAndDate parseCDSTimeFormat(const uint8_t *data, uint8_t length);
/**
* Dummy function created only to access mkUTCtime for testing
* Dummy function created only to access `mkUTCtime` for testing
*
* @todo Delete this function
*/
......@@ -103,7 +105,7 @@ public:
}
/**
* Dummy function created only to access utcTime for testing
* Dummy function created only to access `utcTime` for testing
*
* @todo Delete this function
*/
......@@ -112,8 +114,10 @@ public:
}
};
// used to access `mkgmtime` function and `gmtime` function in the static `implementCDSTimeFormat`
// and in the static `parseCDSTimeFormat functions
/**
* Used to access `mkgmtime` function and `gmtime` function in the static `implementCDSTimeFormat`
* and in the static `parseCDSTimeFormat` functions
*/
static TimeHelper Access;
#endif //ECSS_SERVICES_TIMEHELPER_HPP
......@@ -34,13 +34,13 @@ public:
serviceType = 9;
}
/**
/**
* TM[9,3] CDS time report
*
* This function sends reports with the spacecraft time that is formatted according to the CDS
* time code format(check class `TimeHelper` for the format)
*
* @param TimeInfo the time information/data from the RTC(UTC format)
* @param TimeInfo the time information/data from the RTC(UTC format)
* @todo check if we need spacecraft time reference status
* @todo ECSS standard claims: <<The time reports generated by the time reporting subservice
* are spacecraft time packets. A spacecraft time packet does not carry the message type,
......@@ -58,8 +58,7 @@ public:
* time-management telecommand packet. This data is formatted according to the CDS time code
* format(check class `TimeHelper` for the format)
*
* @param timeData the data of the parsed space packet for the ST[09] time management
* @param length the size of the time data
* @param message the Message that will be parsed for its time-data
*/
struct TimeAndDate cdsTimeRequest(Message &message);
};
......
......@@ -10,26 +10,25 @@ bool TimeHelper::IsLeapYear(uint16_t year) {
return (year % 400) == 0;
}
uint32_t TimeHelper::mkUTCtime(struct TimeAndDate &timeInfo) {
uint32_t TimeHelper::mkUTCtime(struct TimeAndDate &TimeInfo) {
uint32_t secs = 0;
for (uint16_t y = 1970; y < timeInfo.year; ++y) {
for (uint16_t y = 1970; y < TimeInfo.year; ++y) {
secs += (IsLeapYear(y) ? 366 : 365) * SecondsPerDay;
}
for (uint16_t m = 1; m < timeInfo.month; ++m) {
for (uint16_t m = 1; m < TimeInfo.month; ++m) {
secs += DaysOfMonth[m - 1] * SecondsPerDay;
if (m == 2 && IsLeapYear(timeInfo.year)) {
if (m == 2 && IsLeapYear(TimeInfo.year)) {
secs += SecondsPerDay;
}
}
secs += (timeInfo.day - 1) * SecondsPerDay;
secs += timeInfo.hour * SecondsPerHour;
secs += timeInfo.minute * SecondsPerMinute;
secs += timeInfo.second;
secs += (TimeInfo.day - 1) * SecondsPerDay;
secs += TimeInfo.hour * SecondsPerHour;
secs += TimeInfo.minute * SecondsPerMinute;
secs += TimeInfo.second;
return secs;
}
struct TimeAndDate TimeHelper::utcTime(uint32_t seconds) {
struct TimeAndDate TimeInfo = {0};
// Unix epoch 1/1/1970 00:00:00
TimeInfo.year = 1970;
......@@ -92,15 +91,14 @@ uint64_t TimeHelper::implementCDSTimeFormat(struct TimeAndDate &TimeInfo) {
uint32_t seconds = Access.mkUTCtime(TimeInfo);
/**
* The `DAY` segment, 16 bits as defined from standard. Actually the days passed from an
* Agency-defined epoch,that it will be 1 January 1970(1/1/1970) 00:00:00(hours:minutes:seconds)
* This epoch is configured from the current implementation, using mktime() function
* The `DAY` segment, 16 bits as defined from standard. Actually the days passed since Unix
* epoch
*/
auto elapsedDays = static_cast<uint16_t>(seconds / 86400);
/**
* The `ms of day` segment, 32 bits as defined in standard. The `ms of the day` and DAY`
* should give the time passed from the defined epoch (1/1/1970)
* should give the time passed since Unix epoch
*/
auto msOfDay = static_cast<uint32_t >((seconds % 86400) * 1000);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment