From 7dd4694d9d9e25114c6b52f7539ced43b8bdca3f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 28 Jan 2020 23:19:19 +0100 Subject: [PATCH] CCSDS time extra defined for avr lib --- timemanager/CCSDSTime.cpp | 47 +++++++++++++++++++++++++++++--- timemanager/ReceivesTimeInfoIF.h | 1 + 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index 2eb6c4b5..c3a28df7 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -154,6 +154,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* if (length < 19) { return RETURN_FAILED; } +#ifdef AVR_STDIO // In the size optimized nano library used by ATMEL, floating point conversion // is not allowed. There is a linker flag to allow it apparently, but I // could not manage to make it run (removing -specs=nano.specs in linker flags works though, @@ -167,11 +168,8 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* int minute; int second; int usecond; - // try Code A (yyyy-mm-dd) - //int count = sscanf((char *) from, "%4hi-%2hi-%2hiT%2hi:%2hi:%fZ", &year, - // &month, &day, &hour, &minute, &second); int count = sscanf((char *) from, "%4d-%2d-%2dT%2d:%2d:%2d.%dZ", &year, - &month, &day, &hour, &minute, &second, &usecond); + &month, &day, &hour, &minute, &second, &usecond); if (count == 7) { to->year = year; to->month = month; @@ -202,6 +200,47 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* to->usecond = usecond; return RETURN_OK; } +#else + uint16_t year; + uint8_t month; + uint16_t day; + uint8_t hour; + uint8_t minute; + float second; + //try Code A (yyyy-mm-dd) + int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year, + &month, &day, &hour, &minute, &second); + if (count == 6) { + to->year = year; + to->month = month; + to->day = day; + to->hour = hour; + to->minute = minute; + to->second = second; + to->usecond = (second - floor(second)) * 1000000; + return RETURN_OK; + } + + //try Code B (yyyy-ddd) + count = sscanf((char *) from, "%4hi-%3hiT%2hhi:%2hhi:%fZ", &year, &day, + &hour, &minute, &second); + if (count == 5) { + uint8_t tempDay; + ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, &month, + &tempDay); + if (result != RETURN_OK) { + return RETURN_FAILED; + } + to->year = year; + to->month = month; + to->day = tempDay; + to->hour = hour; + to->minute = minute; + to->second = second; + to->usecond = (second - floor(second)) * 1000000; + return RETURN_OK; + } +#endif return UNSUPPORTED_TIME_FORMAT; } diff --git a/timemanager/ReceivesTimeInfoIF.h b/timemanager/ReceivesTimeInfoIF.h index 14a750c5..f65f9dad 100644 --- a/timemanager/ReceivesTimeInfoIF.h +++ b/timemanager/ReceivesTimeInfoIF.h @@ -7,6 +7,7 @@ #ifndef RECEIVESTIMEINFOIF_H_ #define RECEIVESTIMEINFOIF_H_ +#include /** * This is a Interface for classes that receive timing information