CCSDS sscanf function adapted for atmel stdio.c (see comments)
This commit is contained in:
parent
b8af3b5e3d
commit
2b44e1c9c4
@ -154,32 +154,41 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
|||||||
if (length < 19) {
|
if (length < 19) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
uint16_t year;
|
// In the size optimized nano library used by ATMEL, floating point conversion
|
||||||
uint8_t month;
|
// is not allowed. There is a linker flag to allow it apparently, but I
|
||||||
uint16_t day;
|
// could not manage to make it run (removing -specs=nano.specs in linker flags works though,
|
||||||
uint8_t hour;
|
// but we propably should include this). Using floats with sscanf is also expensive.
|
||||||
uint8_t minute;
|
// Furthermore, the stdio.c library by ATMEL can't resolve the %hhi specifiers
|
||||||
float second;
|
// Therefore, I adapted this function.
|
||||||
//try Code A (yyyy-mm-dd)
|
int year;
|
||||||
int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year,
|
int month;
|
||||||
&month, &day, &hour, &minute, &second);
|
int day;
|
||||||
if (count == 6) {
|
int hour;
|
||||||
|
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);
|
||||||
|
if (count == 7) {
|
||||||
to->year = year;
|
to->year = year;
|
||||||
to->month = month;
|
to->month = month;
|
||||||
to->day = day;
|
to->day = day;
|
||||||
to->hour = hour;
|
to->hour = hour;
|
||||||
to->minute = minute;
|
to->minute = minute;
|
||||||
to->second = second;
|
to->second = second;
|
||||||
to->usecond = (second - floor(second)) * 1000000;
|
to->usecond = usecond;//(second - floor(second)) * 1000000;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
//try Code B (yyyy-ddd)
|
// try Code B (yyyy-ddd)
|
||||||
count = sscanf((char *) from, "%4hi-%3hiT%2hhi:%2hhi:%fZ", &year, &day,
|
count = sscanf((char *) from, "%4i-%3iT%2i:%2i:%2i.%iZ", &year, &day,
|
||||||
&hour, &minute, &second);
|
&hour, &minute, &second, &usecond);
|
||||||
if (count == 5) {
|
if (count == 6) {
|
||||||
uint8_t tempDay;
|
uint8_t tempDay;
|
||||||
ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, &month,
|
ReturnValue_t result = CCSDSTime::convertDaysOfYear((uint16_t)day,(uint16_t) year,(uint8_t *) &month,
|
||||||
&tempDay);
|
&tempDay);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
@ -190,7 +199,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
|||||||
to->hour = hour;
|
to->hour = hour;
|
||||||
to->minute = minute;
|
to->minute = minute;
|
||||||
to->second = second;
|
to->second = second;
|
||||||
to->usecond = (second - floor(second)) * 1000000;
|
to->usecond = usecond;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user