Skip to content

Commit

Permalink
Merge pull request #2088 from METECS/main
Browse files Browse the repository at this point in the history
Fix #2084, Add support for fractional seconds in epoch
  • Loading branch information
astrogeco committed May 2, 2022
2 parents 81416f8 + 1725460 commit 9f288e0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions cmake/sample_defs/sample_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@
** Hour - 0 to 23
** Minute - 0 to 59
** Second - 0 to 59
** Micros - 0 to 999999
*/
#define CFE_MISSION_TIME_EPOCH_YEAR 1980
#define CFE_MISSION_TIME_EPOCH_DAY 1
#define CFE_MISSION_TIME_EPOCH_HOUR 0
#define CFE_MISSION_TIME_EPOCH_MINUTE 0
#define CFE_MISSION_TIME_EPOCH_SECOND 0
#define CFE_MISSION_TIME_EPOCH_MICROS 0

/**
** \cfetimecfg Time File System Factor
Expand Down
10 changes: 7 additions & 3 deletions modules/time/fsw/src/cfe_time_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,13 @@ void CFE_TIME_Print(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint)
/*
** Convert the cFE time (offset from epoch) into calendar time...
*/
NumberOfMinutes = (TimeToPrint.Seconds / 60) + CFE_MISSION_TIME_EPOCH_MINUTE;
NumberOfSeconds = (TimeToPrint.Seconds % 60) + CFE_MISSION_TIME_EPOCH_SECOND;
NumberOfMicros = CFE_TIME_Sub2MicroSecs(TimeToPrint.Subseconds) + CFE_MISSION_TIME_EPOCH_MICROS;

NumberOfMinutes = (NumberOfMicros / 60000000) + (TimeToPrint.Seconds / 60) + CFE_MISSION_TIME_EPOCH_MINUTE;
NumberOfMicros = NumberOfMicros % 60000000;

NumberOfSeconds = (NumberOfMicros / 1000000) + (TimeToPrint.Seconds % 60) + CFE_MISSION_TIME_EPOCH_SECOND;
NumberOfMicros = NumberOfMicros % 1000000;
/*
** Adding the epoch "seconds" after computing the minutes avoids
** overflow problems when the input time value (seconds) is
Expand Down Expand Up @@ -698,7 +702,7 @@ void CFE_TIME_Print(char *PrintBuffer, CFE_TIME_SysTime_t TimeToPrint)
/*
** After computing microseconds, convert to 5 digits from 6 digits...
*/
NumberOfMicros = CFE_TIME_Sub2MicroSecs(TimeToPrint.Subseconds) / 10;
NumberOfMicros = NumberOfMicros / 10;

/*
** Build formatted output string (yyyy-ddd-hh:mm:ss.xxxxx)...
Expand Down
2 changes: 1 addition & 1 deletion modules/time/ut-coverage/time_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ void Test_Print(void)
UtPrintf("Begin Test Print");

if (CFE_MISSION_TIME_EPOCH_YEAR != 1980 || CFE_MISSION_TIME_EPOCH_DAY != 1 || CFE_MISSION_TIME_EPOCH_HOUR != 0 ||
CFE_MISSION_TIME_EPOCH_MINUTE != 0 || CFE_MISSION_TIME_EPOCH_SECOND != 0)
CFE_MISSION_TIME_EPOCH_MINUTE != 0 || CFE_MISSION_TIME_EPOCH_SECOND != 0 || CFE_MISSION_TIME_EPOCH_MICROS != 0)
{
UtPrintf("Custom epoch time requires manual inspection for CFE_TIME_Print");
usingDefaultEpoch = false;
Expand Down

0 comments on commit 9f288e0

Please sign in to comment.