Merge pull request 'Newlib nano CCSDS define' (#49) from KSat/fsfw:mueller_CCSDSTime_Bugfix_Atmel into master
Does not hurt anyone.
This commit is contained in:
commit
86c48cb7d8
@ -1,5 +1,6 @@
|
||||
#include <framework/timemanager/CCSDSTime.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
|
||||
CCSDSTime::CCSDSTime() {
|
||||
@ -154,14 +155,16 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
||||
if (length < 19) {
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
// Newlib nano can't parse uint8, see SCNu8 documentation and https://sourceware.org/newlib/README
|
||||
// Suggestion: use uint16 all the time. This should work on all systems.
|
||||
#ifdef NEWLIB_NANO_NO_C99_IO
|
||||
uint16_t year;
|
||||
uint8_t month;
|
||||
uint16_t month;
|
||||
uint16_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint16_t hour;
|
||||
uint16_t minute;
|
||||
float second;
|
||||
//try Code A (yyyy-mm-dd)
|
||||
int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year,
|
||||
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;
|
||||
@ -175,8 +178,51 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
||||
}
|
||||
|
||||
// try Code B (yyyy-ddd)
|
||||
count = sscanf((char *) from, "%4hi-%3hiT%2hhi:%2hhi:%fZ", &year, &day,
|
||||
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));
|
||||
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;
|
||||
}
|
||||
// Warning: Compiler/Linker fails ambiguously if library does not implement
|
||||
// C99 I/O
|
||||
#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, "%4" SCNu16 "-%2" SCNu8 "-%2" SCNu16
|
||||
"T%2" SCNu8 ":%2" SCNu8 ":%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, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu8
|
||||
":%2" SCNu8 ":%fZ", &year, &day, &hour, &minute, &second);
|
||||
if (count == 5) {
|
||||
uint8_t tempDay;
|
||||
ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, &month,
|
||||
@ -193,6 +239,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
||||
to->usecond = (second - floor(second)) * 1000000;
|
||||
return RETURN_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
return UNSUPPORTED_TIME_FORMAT;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user