Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor common logic out of CFE_TIME_SetTime/MET/STCFCmd() #2339

Open
2 tasks done
thnkslprpt opened this issue May 20, 2023 · 0 comments · May be fixed by #2340
Open
2 tasks done

Refactor common logic out of CFE_TIME_SetTime/MET/STCFCmd() #2339

thnkslprpt opened this issue May 20, 2023 · 0 comments · May be fixed by #2340

Comments

@thnkslprpt
Copy link
Contributor

Checklist

  • I reviewed the Contributing Guide.
  • I performed a cursory search to see if the bug report is relevant, not redundant, nor in conflict with other tickets.

Describe the bug
Near-identical logic in CFE_TIME_SetTimeCmd(), CFE_TIME_SetMETCmd() and CFE_TIME_SetSTCFCmd().
Was noted here but doesn't have an issue open that I could find.

Code snips

int32 CFE_TIME_SetTimeCmd(const CFE_TIME_SetTimeCmd_t *data)
{
const CFE_TIME_TimeCmd_Payload_t *CommandPtr = &data->Payload;
/*
** Verify "micro-seconds" command argument...
*/
if (CommandPtr->MicroSeconds < 1000000)
{
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
CFE_TIME_SysTime_t NewTime;
NewTime.Seconds = CommandPtr->Seconds;
NewTime.Subseconds = CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds);
CFE_TIME_SetTime(NewTime);
CFE_TIME_Global.CommandCounter++;
CFE_EVS_SendEvent(CFE_TIME_TIME_EID, CFE_EVS_EventType_INFORMATION,
"Set Time -- secs = %u, usecs = %u, ssecs = 0x%X", (unsigned int)CommandPtr->Seconds,
(unsigned int)CommandPtr->MicroSeconds,
(unsigned int)CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds));
#else /* not CFE_PLATFORM_TIME_CFG_SERVER */
/*
** We want to know if disabled commands are being sent...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_TIME_CFG_EID, CFE_EVS_EventType_ERROR,
"Set Time commands invalid without CFE_PLATFORM_TIME_CFG_SERVER set to TRUE");
#endif /* CFE_PLATFORM_TIME_CFG_SERVER */
}
else
{
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_TIME_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Time -- secs = %u, usecs = %u",
(unsigned int)CommandPtr->Seconds, (unsigned int)CommandPtr->MicroSeconds);
}
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_SetMETCmd(const CFE_TIME_SetMETCmd_t *data)
{
const CFE_TIME_TimeCmd_Payload_t *CommandPtr = &data->Payload;
/*
** Verify "micro-seconds" command argument...
*/
if (CommandPtr->MicroSeconds < 1000000)
{
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
CFE_TIME_SysTime_t NewMET;
NewMET.Seconds = CommandPtr->Seconds;
NewMET.Subseconds = CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds);
CFE_TIME_SetMET(NewMET);
CFE_TIME_Global.CommandCounter++;
CFE_EVS_SendEvent(CFE_TIME_MET_EID, CFE_EVS_EventType_INFORMATION,
"Set MET -- secs = %u, usecs = %u, ssecs = 0x%X", (unsigned int)CommandPtr->Seconds,
(unsigned int)CommandPtr->MicroSeconds,
(unsigned int)CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds));
#else /* not CFE_PLATFORM_TIME_CFG_SERVER */
/*
** We want to know if disabled commands are being sent...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_MET_CFG_EID, CFE_EVS_EventType_ERROR,
"Set MET commands invalid without CFE_PLATFORM_TIME_CFG_SERVER set to TRUE");
#endif /* CFE_PLATFORM_TIME_CFG_SERVER */
}
else
{
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_MET_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid MET -- secs = %u, usecs = %u",
(unsigned int)CommandPtr->Seconds, (unsigned int)CommandPtr->MicroSeconds);
}
return CFE_SUCCESS;
}
/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
int32 CFE_TIME_SetSTCFCmd(const CFE_TIME_SetSTCFCmd_t *data)
{
const CFE_TIME_TimeCmd_Payload_t *CommandPtr = &data->Payload;
/*
** Verify "micro-seconds" command argument...
*/
if (CommandPtr->MicroSeconds < 1000000)
{
#if (CFE_PLATFORM_TIME_CFG_SERVER == true)
CFE_TIME_SysTime_t NewSTCF;
NewSTCF.Seconds = CommandPtr->Seconds;
NewSTCF.Subseconds = CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds);
CFE_TIME_SetSTCF(NewSTCF);
CFE_TIME_Global.CommandCounter++;
CFE_EVS_SendEvent(CFE_TIME_STCF_EID, CFE_EVS_EventType_INFORMATION,
"Set STCF -- secs = %u, usecs = %u, ssecs = 0x%X", (unsigned int)CommandPtr->Seconds,
(unsigned int)CommandPtr->MicroSeconds,
(unsigned int)CFE_TIME_Micro2SubSecs(CommandPtr->MicroSeconds));
#else /* not CFE_PLATFORM_TIME_CFG_SERVER */
/*
** We want to know if disabled commands are being sent...
*/
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_STCF_CFG_EID, CFE_EVS_EventType_ERROR,
"Set STCF commands invalid without CFE_PLATFORM_TIME_CFG_SERVER set to TRUE");
#endif /* CFE_PLATFORM_TIME_CFG_SERVER */
}
else
{
CFE_TIME_Global.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_TIME_STCF_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid STCF -- secs = %u, usecs = %u",
(unsigned int)CommandPtr->Seconds, (unsigned int)CommandPtr->MicroSeconds);
}
return CFE_SUCCESS;
}

Expected behavior
Pull common logic out into a helper function to reduce duplication and make code more readable/maintainable.

Reporter Info
Avi Weiss @thnkslprpt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants