Skip to content

Commit

Permalink
Fix nasa#2341, Rename TimeA/TimeB parameter to improve consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Apr 19, 2024
1 parent 28a5820 commit 232e463
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 87 deletions.
14 changes: 7 additions & 7 deletions docs/cFE Application Developers Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -3496,10 +3496,10 @@ hours later.
The rule that is used by the `CFE_TIME_Compare` function is that if the
smaller delta time is found going in a counter-clockwise direction, then
the first time is considered greater than the second and the comparison
function would return `CFE_TIME_A_GT_B`. Likewise, if the smaller
function would return `CFE_TIME_1_GT_2`. Likewise, if the smaller
delta time is found going in a clockwise direction, as demonstrated in
the example above, then the first time is less than the second and the
comparison function would return `CFE_TIME_A_LT_B`. This rule was
comparison function would return `CFE_TIME_1_LT_2`. This rule was
chosen because it seemed unlikely that someone would require the ability
to compare two times whose delta time was greater than or equal to
2,147,483,647 seconds (approximately 68 years). If a mission does
Expand All @@ -3519,18 +3519,18 @@ time between two absolute times could either be 5 hours or 7 hours. An
example of a delta time computation function is shown below:

```c
CFE_TIME_SysTime_t ComputeDeltaTime(CFE_TIME_SysTime_t TimeA,
CFE_TIME_SysTime_t TimeB)
CFE_TIME_SysTime_t ComputeDeltaTime(CFE_TIME_SysTime_t Time1,
CFE_TIME_SysTime_t Time2)
{
CFE_TIME_SysTime_t Result;

if (CFE_TIME_Compare(TimeA, TimeB) == CFE_TIME_A_GT_B)
if (CFE_TIME_Compare(Time1, Time2) == CFE_TIME_1_GT_2)
{
Result = CFE_TIME_Subtract(TimeA, TimeB);
Result = CFE_TIME_Subtract(Time1, Time2);
}
else
{
Result = CFE_TIME_Subtract(TimeB, TimeA);
Result = CFE_TIME_Subtract(Time2, Time1);
}

return Result;
Expand Down
2 changes: 1 addition & 1 deletion modules/cfe_testcase/src/es_behavior_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void TestWaitBehavior(void)
end = CFE_TIME_GetTime();
TimePassed = CFE_TIME_Subtract(end, start);

UtAssert_UINT32_EQ(CFE_TIME_Compare(TimePassed, TimeExpected), CFE_TIME_A_LT_B);
UtAssert_UINT32_EQ(CFE_TIME_Compare(TimePassed, TimeExpected), CFE_TIME_1_LT_2);
}

void ESBehaviorestSetup(void)
Expand Down
8 changes: 4 additions & 4 deletions modules/cfe_testcase/src/time_arithmetic_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ void TestTimeCompare(void)
UtPrintf("Testing: CFE_TIME_Compare");
CFE_TIME_SysTime_t time1 = {1000, 1000};
CFE_TIME_SysTime_t time2 = {999, 999};
UtAssert_UINT32_EQ(CFE_TIME_Compare(time1, time2), CFE_TIME_A_GT_B);
UtAssert_UINT32_EQ(CFE_TIME_Compare(time2, time1), CFE_TIME_A_LT_B);
UtAssert_UINT32_EQ(CFE_TIME_Compare(time1, time2), CFE_TIME_1_GT_2);
UtAssert_UINT32_EQ(CFE_TIME_Compare(time2, time1), CFE_TIME_1_LT_2);

time1.Seconds = 500;
time1.Subseconds = 1;
Expand All @@ -113,8 +113,8 @@ void TestTimeCompare(void)
time1.Subseconds = 1;
time2.Seconds = UINT32_MAX;
time2.Subseconds = UINT32_MAX;
UtAssert_UINT32_EQ(CFE_TIME_Compare(time1, time2), CFE_TIME_A_GT_B);
UtAssert_UINT32_EQ(CFE_TIME_Compare(time2, time1), CFE_TIME_A_LT_B);
UtAssert_UINT32_EQ(CFE_TIME_Compare(time1, time2), CFE_TIME_1_GT_2);
UtAssert_UINT32_EQ(CFE_TIME_Compare(time2, time1), CFE_TIME_1_LT_2);
}

void TimeArithmeticTestSetup(void)
Expand Down
4 changes: 2 additions & 2 deletions modules/cfe_testcase/src/time_current_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ void TimeInRange(CFE_TIME_SysTime_t Start, CFE_TIME_SysTime_t Time, CFE_TIME_Sys
CFE_TIME_Print(TimeStr, Time);

Compare = CFE_TIME_Compare(Start, Time);
UtAssert_True((Compare == CFE_TIME_EQUAL) || (Compare == CFE_TIME_A_LT_B), "%s: %lu %lu (%s) <= %lu %lu (%s)", Str,
UtAssert_True((Compare == CFE_TIME_EQUAL) || (Compare == CFE_TIME_1_LT_2), "%s: %lu %lu (%s) <= %lu %lu (%s)", Str,
(long unsigned)Start.Seconds, (long unsigned)Start.Subseconds, StartStr, (long unsigned)Time.Seconds,
(long unsigned)Time.Subseconds, TimeStr);

Delta = CFE_TIME_Subtract(Time, Start);
Compare = CFE_TIME_Compare(Delta, Range);
UtAssert_True((Compare == CFE_TIME_EQUAL) || (Compare == CFE_TIME_A_LT_B), "%s: Delta %lu %lu <= Range %lu %lu",
UtAssert_True((Compare == CFE_TIME_EQUAL) || (Compare == CFE_TIME_1_LT_2), "%s: Delta %lu %lu <= Range %lu %lu",
Str, (long unsigned)Delta.Seconds, (long unsigned)Delta.Subseconds, (long unsigned)Range.Seconds,
(long unsigned)Range.Subseconds);
}
Expand Down
18 changes: 9 additions & 9 deletions modules/core_api/fsw/inc/cfe_time.h
Original file line number Diff line number Diff line change
Expand Up @@ -372,27 +372,27 @@ CFE_TIME_SysTime_t CFE_TIME_Subtract(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_
** strange cases that result from these situations can be handled by defining
** the comparison function for times as follows:
** Plot the two times on the circumference of a circle where 0 is at the
** top and 0x80000000 is at the bottom. If the shortest arc from time A
** to time B runs clockwise around the circle, then time A is less than
** time B. If the shortest arc from A to B runs counter-clockwise, then
** time A is greater than time B.
** top and 0x80000000 is at the bottom. If the shortest arc from time 1
** to time 2 runs clockwise around the circle, then time 1 is less than
** time 2. If the shortest arc from 1 to 2 runs counter-clockwise, then
** time 1 is greater than time 2.
**
** \par Assumptions, External Events, and Notes:
** None
**
** \param[in] TimeA The first time to compare.
** \param[in] Time1 The first time to compare.
**
** \param[in] TimeB The second time to compare.
** \param[in] Time2 The second time to compare.
**
** \return The result of comparing the two times.
** \retval #CFE_TIME_EQUAL \copybrief CFE_TIME_EQUAL
** \retval #CFE_TIME_A_GT_B \copybrief CFE_TIME_A_GT_B
** \retval #CFE_TIME_A_LT_B \copybrief CFE_TIME_A_LT_B
** \retval #CFE_TIME_1_GT_2 \copybrief CFE_TIME_1_GT_2
** \retval #CFE_TIME_1_LT_2 \copybrief CFE_TIME_1_LT_2
**
** \sa #CFE_TIME_Add, #CFE_TIME_Subtract
**
******************************************************************************/
CFE_TIME_Compare_t CFE_TIME_Compare(CFE_TIME_SysTime_t TimeA, CFE_TIME_SysTime_t TimeB);
CFE_TIME_Compare_t CFE_TIME_Compare(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_t Time2);
/**@}*/

/** @defgroup CFEAPITIMEConvert cFE Time Conversion APIs
Expand Down
4 changes: 2 additions & 2 deletions modules/core_api/fsw/inc/cfe_time_api_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@
*/
typedef enum CFE_TIME_Compare
{
CFE_TIME_A_LT_B = -1, /**< \brief The first specified time is considered to be before the second specified time */
CFE_TIME_1_LT_2 = -1, /**< \brief The first specified time is considered to be before the second specified time */
CFE_TIME_EQUAL = 0, /**< \brief The two specified times are considered to be equal */
CFE_TIME_A_GT_B = 1 /**< \brief The first specified time is considered to be after the second specified time */
CFE_TIME_1_GT_2 = 1 /**< \brief The first specified time is considered to be after the second specified time */
} CFE_TIME_Compare_t;

/**
Expand Down
6 changes: 3 additions & 3 deletions modules/core_api/ut-stubs/src/cfe_time_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ CFE_TIME_SysTime_t CFE_TIME_Add(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_t Tim
* Generated stub function for CFE_TIME_Compare()
* ----------------------------------------------------
*/
CFE_TIME_Compare_t CFE_TIME_Compare(CFE_TIME_SysTime_t TimeA, CFE_TIME_SysTime_t TimeB)
CFE_TIME_Compare_t CFE_TIME_Compare(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_t Time2)
{
UT_GenStub_SetupReturnBuffer(CFE_TIME_Compare, CFE_TIME_Compare_t);

UT_GenStub_AddParam(CFE_TIME_Compare, CFE_TIME_SysTime_t, TimeA);
UT_GenStub_AddParam(CFE_TIME_Compare, CFE_TIME_SysTime_t, TimeB);
UT_GenStub_AddParam(CFE_TIME_Compare, CFE_TIME_SysTime_t, Time1);
UT_GenStub_AddParam(CFE_TIME_Compare, CFE_TIME_SysTime_t, Time2);

UT_GenStub_Execute(CFE_TIME_Compare, Basic, NULL);

Expand Down
26 changes: 13 additions & 13 deletions modules/time/fsw/src/cfe_time_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,50 +452,50 @@ CFE_TIME_SysTime_t CFE_TIME_Subtract(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_TIME_Compare_t CFE_TIME_Compare(CFE_TIME_SysTime_t TimeA, CFE_TIME_SysTime_t TimeB)
CFE_TIME_Compare_t CFE_TIME_Compare(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_t Time2)
{
CFE_TIME_Compare_t Result;

if (TimeA.Seconds > TimeB.Seconds)
if (Time1.Seconds > Time2.Seconds)
{
/*
** Assume rollover if difference is too large...
*/
if ((TimeA.Seconds - TimeB.Seconds) > CFE_TIME_NEGATIVE)
if ((Time1.Seconds - Time2.Seconds) > CFE_TIME_NEGATIVE)
{
Result = CFE_TIME_A_LT_B;
Result = CFE_TIME_1_LT_2;
}
else
{
Result = CFE_TIME_A_GT_B;
Result = CFE_TIME_1_GT_2;
}
}
else if (TimeA.Seconds < TimeB.Seconds)
else if (Time1.Seconds < Time2.Seconds)
{
/*
** Assume rollover if difference is too large...
*/
if ((TimeB.Seconds - TimeA.Seconds) > CFE_TIME_NEGATIVE)
if ((Time2.Seconds - Time1.Seconds) > CFE_TIME_NEGATIVE)
{
Result = CFE_TIME_A_GT_B;
Result = CFE_TIME_1_GT_2;
}
else
{
Result = CFE_TIME_A_LT_B;
Result = CFE_TIME_1_LT_2;
}
}
else
{
/*
** Seconds are equal, check sub-seconds
*/
if (TimeA.Subseconds > TimeB.Subseconds)
if (Time1.Subseconds > Time2.Subseconds)
{
Result = CFE_TIME_A_GT_B;
Result = CFE_TIME_1_GT_2;
}
else if (TimeA.Subseconds < TimeB.Subseconds)
else if (Time1.Subseconds < Time2.Subseconds)
{
Result = CFE_TIME_A_LT_B;
Result = CFE_TIME_1_LT_2;
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions modules/time/fsw/src/cfe_time_tone.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ int32 CFE_TIME_ToneSendMET(CFE_TIME_SysTime_t NewMET)
** Ignore bad external time data only if clock state is valid...
*/
if ((Reference.ClockSetState == CFE_TIME_SetState_WAS_SET) &&
((MinResult == CFE_TIME_A_LT_B) || (MaxResult == CFE_TIME_A_GT_B)))
((MinResult == CFE_TIME_1_LT_2) || (MaxResult == CFE_TIME_1_GT_2)))
{
Result = CFE_TIME_OUT_OF_RANGE;

Expand Down Expand Up @@ -375,7 +375,7 @@ int32 CFE_TIME_ToneSendGPS(CFE_TIME_SysTime_t NewTime, int16 NewLeaps)
** If state is valid then ignore bad external time data...
*/
if ((Reference.ClockSetState == CFE_TIME_SetState_WAS_SET) &&
((MinResult == CFE_TIME_A_LT_B) || (MaxResult == CFE_TIME_A_GT_B)))
((MinResult == CFE_TIME_1_LT_2) || (MaxResult == CFE_TIME_1_GT_2)))
{
Result = CFE_TIME_OUT_OF_RANGE;

Expand Down Expand Up @@ -513,7 +513,7 @@ int32 CFE_TIME_ToneSendTime(CFE_TIME_SysTime_t NewTime)
** If state is valid then ignore bad external time data...
*/
if ((Reference.ClockSetState == CFE_TIME_SetState_WAS_SET) &&
((MinResult == CFE_TIME_A_LT_B) || (MaxResult == CFE_TIME_A_GT_B)))
((MinResult == CFE_TIME_1_LT_2) || (MaxResult == CFE_TIME_1_GT_2)))
{
Result = CFE_TIME_OUT_OF_RANGE;

Expand Down Expand Up @@ -707,7 +707,7 @@ void CFE_TIME_ToneVerify(CFE_TIME_SysTime_t Time1, CFE_TIME_SysTime_t Time2)
** Compute elapsed time between tone and data packet...
*/
result = CFE_TIME_Compare(Time1, Time2);
if (result == CFE_TIME_A_GT_B)
if (result == CFE_TIME_1_GT_2)
{
/*
** Local clock has rolled over...
Expand Down Expand Up @@ -979,7 +979,7 @@ void CFE_TIME_Tone1HzISR(void)
*/
Result = CFE_TIME_Compare(ToneSignalLatch, CFE_TIME_Global.ToneSignalLatch);

if (Result == CFE_TIME_A_LT_B)
if (Result == CFE_TIME_1_LT_2)
{
/*
** Local clock has rolled over...
Expand Down
2 changes: 1 addition & 1 deletion modules/time/fsw/src/cfe_time_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void CFE_TIME_GetReference(CFE_TIME_Reference_t *Reference)
/*
** Compute the amount of time "since" the tone...
*/
if (CFE_TIME_Compare(Reference->CurrentLatch, Reference->AtToneLatch) == CFE_TIME_A_LT_B)
if (CFE_TIME_Compare(Reference->CurrentLatch, Reference->AtToneLatch) == CFE_TIME_1_LT_2)
{
/*
** Local clock has rolled over since last tone...
Expand Down
Loading

0 comments on commit 232e463

Please sign in to comment.