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

Fix #108, dispatch pattern for SC #111

Merged
merged 1 commit into from
Oct 5, 2023
Merged

Conversation

jphickey
Copy link
Contributor

Checklist (Please check before submitting)

Describe the contribution
Move switch statements to a separate dispatch source file, and update all unit tests accordingly.

All business logic of commands is put into separate command handler functions in sc_cmds.c. No logic is inside the switch statement, outside of message validation.

Fixes #108

Testing performed
Build and run SC and all tests

Expected behavior changes
No external/observable behavior change

System(s) tested on
Debian

Additional context
Intent is to improve code consistency, ease future maintenance, and to match patterns used elsewhere.

Contributor Info - All information REQUIRED for consideration of pull request
Joseph Hickey, Vantage Systems, Inc.

/* Process a command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SC_ProcessCommand(const CFE_SB_Buffer_t *BufPtr)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
/* Process Requests */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SC_ProcessRequest(const CFE_SB_Buffer_t *BufPtr)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
/* SC Verify the length of the command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
bool SC_VerifyCmdLength(const CFE_MSG_Message_t *Msg, size_t ExpectedLength)

Check notice

Code scanning / CodeQL

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
fsw/src/sc_cmds.c Fixed Show fixed Hide fixed
fsw/src/sc_cmds.c Fixed Show fixed Hide fixed
Comment on lines +540 to +581
if (SC_AppData.NextProcNumber == SC_RTP)
{
/* set during init to power on or processor reset auto-exec RTS */
if (SC_AppData.AutoStartRTS != 0)
{
/* make sure the selected auto-exec RTS is enabled */
if (SC_OperData.RtsInfoTblAddr[SC_RTS_NUM_TO_INDEX(SC_AppData.AutoStartRTS)].RtsStatus == SC_LOADED)
{
SC_OperData.RtsInfoTblAddr[SC_RTS_NUM_TO_INDEX(SC_AppData.AutoStartRTS)].DisabledFlag = false;
}

/* send ground cmd to have SC start the RTS */
SC_AutoStartRts(SC_AppData.AutoStartRTS);

/* only start it once */
SC_AppData.AutoStartRTS = 0;
}

/* request from health and safety for housekeeping status */
SC_SendHkPacket();
SC_ProcessRtpCommand();
}
break;
}

case SC_1HZ_WAKEUP_MID:
/*
** Time to execute a command in the SC memory
*/
do
SC_UpdateNextTime();
if ((SC_AppData.NextProcNumber == SC_NONE) ||
(SC_AppData.NextCmdTime[SC_AppData.NextProcNumber] > SC_AppData.CurrentTime))
{
SC_OperData.NumCmdsSec = 0;
IsThereAnotherCommandToExecute = false;
}
else /* Command needs to run immediately */
{
if (SC_OperData.NumCmdsSec >= SC_MAX_CMDS_PER_SEC)
{
/*
** Check to see if there is an ATS switch Pending, if so service it.
*/
if (SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag == true)
{
SC_ServiceSwitchPend();
}

if (SC_AppData.NextProcNumber == SC_ATP)
{
SC_ProcessAtpCmd();
}
else
{
if (SC_AppData.NextProcNumber == SC_RTP)
{
SC_ProcessRtpCommand();
}
}

SC_UpdateNextTime();
if ((SC_AppData.NextProcNumber == SC_NONE) ||
(SC_AppData.NextCmdTime[SC_AppData.NextProcNumber] > SC_AppData.CurrentTime))
{
SC_OperData.NumCmdsSec = 0;
IsThereAnotherCommandToExecute = false;
}
else /* Command needs to run immediately */
{
if (SC_OperData.NumCmdsSec >= SC_MAX_CMDS_PER_SEC)
{
SC_OperData.NumCmdsSec = 0;
IsThereAnotherCommandToExecute = false;
}
else
{
IsThereAnotherCommandToExecute = true;
}
}
} while (IsThereAnotherCommandToExecute);

break;

default:
CFE_EVS_SendEvent(SC_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid command pipe message ID: 0x%08lX",
(unsigned long)CFE_SB_MsgIdToValue(MessageID));

SC_OperData.HkPacket.Payload.CmdErrCtr++;
break;
} /* end switch */
SC_OperData.NumCmdsSec = 0;
IsThereAnotherCommandToExecute = false;
}
else
{
IsThereAnotherCommandToExecute = true;
}
}
} while (IsThereAnotherCommandToExecute);

Check warning

Code scanning / CodeQL

Unbounded loop Warning

This loop does not have a fixed bound.
/* Process a command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SC_ProcessCommand(const CFE_SB_Buffer_t *BufPtr)

Check notice

Code scanning / CodeQL

Function too long Note

SC_ProcessCommand has too many lines (141, while 60 are allowed).
/* Process a command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SC_ProcessCommand(const CFE_SB_Buffer_t *BufPtr)

Check warning

Code scanning / CodeQL

Poorly documented large function Warning

Poorly documented function: fewer than 2% comments for a function of 141 lines.
@jphickey
Copy link
Contributor Author

Workflow failure currently reported in this PR should be fixed by my other pending PRs. Once reviewed and merged I this can be rebased.

fsw/src/sc_cmds.c Fixed Show fixed Hide fixed
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL-coding-standard found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

Move switch statements to a separate dispatch source file, and update
all unit tests accordingly.

All business logic of commands is put into separate command handler
functions in sc_cmds.c.  No logic is inside the switch statement,
outside of message validation.
@jphickey
Copy link
Contributor Author

Everything rebased and tests/workflows are passing.

@dzbaker dzbaker merged commit fb6a45f into nasa:main Oct 5, 2023
17 checks passed
@jphickey jphickey deleted the fix-108-dispatcher branch October 6, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement dispatch pattern in SC
2 participants