Skip to content

Commit f5835d9

Browse files
author
Jonathan Brandenburg
committed
Fix #2084, Add support for fractional seconds in epoch
1 parent a6c6b65 commit f5835d9

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

cmake/sample_defs/sample_mission_cfg.h

+2
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,14 @@
180180
** Hour - 0 to 23
181181
** Minute - 0 to 59
182182
** Second - 0 to 59
183+
** Micros - 0 to 999999
183184
*/
184185
#define CFE_MISSION_TIME_EPOCH_YEAR 1980
185186
#define CFE_MISSION_TIME_EPOCH_DAY 1
186187
#define CFE_MISSION_TIME_EPOCH_HOUR 0
187188
#define CFE_MISSION_TIME_EPOCH_MINUTE 0
188189
#define CFE_MISSION_TIME_EPOCH_SECOND 0
190+
#define CFE_MISSION_TIME_EPOCH_MICROS 0
189191

190192
/**
191193
** \cfetimecfg Time File System Factor

modules/time/fsw/src/cfe_time_api.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -619,9 +619,13 @@ void CFE_TIME_Print(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint)
619619
/*
620620
** Convert the cFE time (offset from epoch) into calendar time...
621621
*/
622-
NumberOfMinutes = (TimeToPrint.Seconds / 60) + CFE_MISSION_TIME_EPOCH_MINUTE;
623-
NumberOfSeconds = (TimeToPrint.Seconds % 60) + CFE_MISSION_TIME_EPOCH_SECOND;
622+
NumberOfMicros = CFE_TIME_Sub2MicroSecs(TimeToPrint.Subseconds) + CFE_MISSION_TIME_EPOCH_MICROS;
624623

624+
NumberOfMinutes = (NumberOfMicros / 60000000) + (TimeToPrint.Seconds / 60) + CFE_MISSION_TIME_EPOCH_MINUTE;
625+
NumberOfMicros = NumberOfMicros % 60000000;
626+
627+
NumberOfSeconds = (NumberOfMicros / 1000000) + (TimeToPrint.Seconds % 60) + CFE_MISSION_TIME_EPOCH_SECOND;
628+
NumberOfMicros = NumberOfMicros % 1000000;
625629
/*
626630
** Adding the epoch "seconds" after computing the minutes avoids
627631
** overflow problems when the input time value (seconds) is
@@ -698,7 +702,7 @@ void CFE_TIME_Print(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint)
698702
/*
699703
** After computing microseconds, convert to 5 digits from 6 digits...
700704
*/
701-
NumberOfMicros = CFE_TIME_Sub2MicroSecs(TimeToPrint.Subseconds) / 10;
705+
NumberOfMicros = NumberOfMicros / 10;
702706

703707
/*
704708
** Build formatted output string (yyyy-ddd-hh:mm:ss.xxxxx)...

modules/time/ut-coverage/time_UT.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ void Test_Print(void)
837837
UtPrintf("Begin Test Print");
838838

839839
if (CFE_MISSION_TIME_EPOCH_YEAR != 1980 || CFE_MISSION_TIME_EPOCH_DAY != 1 || CFE_MISSION_TIME_EPOCH_HOUR != 0 ||
840-
CFE_MISSION_TIME_EPOCH_MINUTE != 0 || CFE_MISSION_TIME_EPOCH_SECOND != 0)
840+
CFE_MISSION_TIME_EPOCH_MINUTE != 0 || CFE_MISSION_TIME_EPOCH_SECOND != 0 || CFE_MISSION_TIME_EPOCH_MICROS != 0)
841841
{
842842
UtPrintf("Custom epoch time requires manual inspection for CFE_TIME_Print");
843843
usingDefaultEpoch = false;

0 commit comments

Comments
 (0)