WIP: somethings wrong.. #19
@ -1,5 +1,6 @@
|
|||||||
#include <framework/timemanager/CCSDSTime.h>
|
#include <framework/timemanager/CCSDSTime.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
CCSDSTime::CCSDSTime() {
|
CCSDSTime::CCSDSTime() {
|
||||||
@ -154,39 +155,33 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
|||||||
if (length < 19) {
|
if (length < 19) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
}
|
}
|
||||||
#ifdef AVR_STDIO
|
// Newlib can't parse uint8 (there is a configure option but I still need to figure out how to make it work..)
|
||||||
// In the size optimized nano library used by ATMEL, floating point conversion
|
#ifdef NEWLIB_NO_C99_IO
|
||||||
// is not allowed. There is a linker flag to allow it apparently, but I
|
uint16_t year;
|
||||||
// could not manage to make it run (removing -specs=nano.specs in linker flags works though,
|
uint16_t month;
|
||||||
// but we propably should include this). Using floats with sscanf is also expensive.
|
uint16_t day;
|
||||||
// Furthermore, the stdio.c library by ATMEL can't resolve the %hhi specifiers
|
uint16_t hour;
|
||||||
// Therefore, I adapted this function.
|
uint16_t minute;
|
||||||
int year;
|
float second;
|
||||||
int month;
|
int count = sscanf((char *) from, "%4" SCNu16 "-%2" SCNu16 "-%2" SCNu16 "T%2" SCNu16 ":%2" SCNu16 ":%fZ", &year,
|
||||||
int day;
|
&month, &day, &hour, &minute, &second);
|
||||||
int hour;
|
if (count == 6) {
|
||||||
int minute;
|
|
||||||
int second;
|
|
||||||
int usecond;
|
|
||||||
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 = usecond;//(second - floor(second)) * 1000000;
|
to->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, "%4i-%3iT%2i:%2i:%2i.%iZ", &year, &day,
|
count = sscanf((char *) from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu16 ":%2" SCNu16 ":%fZ", &year, &day,
|
||||||
&hour, &minute, &second, &usecond);
|
&hour, &minute, &second);
|
||||||
if (count == 6) {
|
if (count == 5) {
|
||||||
uint8_t tempDay;
|
uint8_t tempDay;
|
||||||
ReturnValue_t result = CCSDSTime::convertDaysOfYear((uint16_t)day,(uint16_t) year,(uint8_t *) &month,
|
ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year,(uint8_t *) &month,
|
||||||
&tempDay);
|
&tempDay);
|
||||||
if (result != RETURN_OK) {
|
if (result != RETURN_OK) {
|
||||||
return RETURN_FAILED;
|
return RETURN_FAILED;
|
||||||
@ -197,7 +192,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 = usecond;
|
to->usecond = (second - floor(second)) * 1000000;
|
||||||
return RETURN_OK;
|
return RETURN_OK;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -208,7 +203,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t*
|
|||||||
uint8_t minute;
|
uint8_t minute;
|
||||||
float second;
|
float second;
|
||||||
//try Code A (yyyy-mm-dd)
|
//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" SCNu8 "-%2" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year,
|
||||||
&month, &day, &hour, &minute, &second);
|
&month, &day, &hour, &minute, &second);
|
||||||
if (count == 6) {
|
if (count == 6) {
|
||||||
to->year = year;
|
to->year = year;
|
||||||
|
Loading…
Reference in New Issue
Block a user