From 61fd5d1b62fe3149b193c6c4175cb9b57cbe67f1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 11 Nov 2022 14:12:42 +0100 Subject: [PATCH] impl function to generate ASCII timestamp sec accuracy --- src/fsfw/timemanager/CCSDSTime.cpp | 15 +++++++++++++-- src/fsfw/timemanager/CCSDSTime.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/fsfw/timemanager/CCSDSTime.cpp b/src/fsfw/timemanager/CCSDSTime.cpp index cf4dbe74..535b18a2 100644 --- a/src/fsfw/timemanager/CCSDSTime.cpp +++ b/src/fsfw/timemanager/CCSDSTime.cpp @@ -246,8 +246,19 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* return UNSUPPORTED_TIME_FORMAT; } -ReturnValue_t CCSDSTime::convertToASCII(int8_t* to, const Clock::TimeOfDay_t* from, - uint8_t length) { +ReturnValue_t CCSDSTime::convertToAsciiWithSecs(int8_t* to, const Clock::TimeOfDay_t* from, + uint8_t length) { + if(from == nullptr or to == nullptr) { + return returnvalue::FAILED; + } + int count = snprintf(reinterpret_cast(to), length, + "%4" SCNu32 "-%2" SCNu32 "-%2" SCNu32 + "T%" + "2" SCNu32 ":%2" SCNu32 ":%2" SCNu32, + from->year, from->month, from->day, from->hour, from->minute, from->second); + if(count >= length) { + return returnvalue::FAILED; + } return returnvalue::OK; } diff --git a/src/fsfw/timemanager/CCSDSTime.h b/src/fsfw/timemanager/CCSDSTime.h index 1ba94e2c..0d4b6e61 100644 --- a/src/fsfw/timemanager/CCSDSTime.h +++ b/src/fsfw/timemanager/CCSDSTime.h @@ -207,7 +207,7 @@ class CCSDSTime { static ReturnValue_t convertFromASCII(Clock::TimeOfDay_t *to, uint8_t const *from, uint8_t length); - static ReturnValue_t convertToASCII(int8_t *to, const Clock::TimeOfDay_t *from, uint8_t length); + static ReturnValue_t convertToAsciiWithSecs(int8_t *to, const Clock::TimeOfDay_t *from, uint8_t length); static uint32_t subsecondsToMicroseconds(uint16_t subseconds); private: