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

CS_RecomputeBaselineMemoryCmd can be simplified by initializing State to CS_STATE_UNDEFINED #109

Open
2 tasks done
thnkslprpt opened this issue Nov 30, 2024 · 0 comments · May be fixed by #110
Open
2 tasks done

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
State is only used in one event message, and initializing to CS_STATE_UNDEFINED would simplify the if/else before the event is sent.

Code snips

CS/fsw/src/cs_memory_cmds.c

Lines 146 to 216 in f958cc0

void CS_RecomputeBaselineMemoryCmd(const CS_EntryCmd_t *CmdPtr)
{
/* command verification variables */
CFE_ES_TaskId_t ChildTaskID = CFE_ES_TASKID_UNDEFINED;
CFE_Status_t Status = CS_ERROR;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
EntryID = CmdPtr->Payload.EntryID;
if (CS_AppData.HkPacket.Payload.RecomputeInProgress == false && CS_AppData.HkPacket.Payload.OneShotInProgress == false)
{
/* make sure the entry is a valid number and is defined in the table */
if ((EntryID < CS_MAX_NUM_MEMORY_TABLE_ENTRIES) &&
(CS_AppData.ResMemoryTblPtr[EntryID].State != CS_STATE_EMPTY))
{
/* There is no child task running right now, we can use it*/
CS_AppData.HkPacket.Payload.RecomputeInProgress = true;
/* fill in child task variables */
CS_AppData.ChildTaskTable = CS_MEMORY_TABLE;
CS_AppData.ChildTaskEntryID = EntryID;
CS_AppData.RecomputeEepromMemoryEntryPtr = &CS_AppData.ResMemoryTblPtr[EntryID];
Status =
CFE_ES_CreateChildTask(&ChildTaskID, CS_RECOMP_MEMORY_TASK_NAME, CS_RecomputeEepromMemoryChildTask,
NULL, CFE_PLATFORM_ES_DEFAULT_STACK_SIZE, CS_CHILD_TASK_PRIORITY, 0);
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(CS_RECOMPUTE_MEMORY_STARTED_DBG_EID, CFE_EVS_EventType_DEBUG,
"Recompute baseline of Memory Entry ID %d started", EntryID);
CS_AppData.HkPacket.Payload.CmdCounter++;
}
else /* child task creation failed */
{
CFE_EVS_SendEvent(
CS_RECOMPUTE_MEMORY_CREATE_CHDTASK_ERR_EID, CFE_EVS_EventType_ERROR,
"Recompute baseline of Memory Entry ID %d failed, ES_CreateChildTask returned: 0x%08X",
EntryID, (unsigned int)Status);
CS_AppData.HkPacket.Payload.CmdErrCounter++;
CS_AppData.HkPacket.Payload.RecomputeInProgress = false;
}
}
else
{
if (EntryID >= CS_MAX_NUM_MEMORY_TABLE_ENTRIES)
{
State = CS_STATE_UNDEFINED;
}
else
{
State = CS_AppData.ResMemoryTblPtr[EntryID].State;
}
CFE_EVS_SendEvent(
CS_RECOMPUTE_INVALID_ENTRY_MEMORY_ERR_EID, CFE_EVS_EventType_ERROR,
"Memory recompute baseline of entry failed, Entry ID invalid: %d, State: %d, Max ID: %d", EntryID,
State, (CS_MAX_NUM_MEMORY_TABLE_ENTRIES - 1));
CS_AppData.HkPacket.Payload.CmdErrCounter++;
}
}
else
{
/*send event that we can't start another task right now */
CFE_EVS_SendEvent(CS_RECOMPUTE_MEMORY_CHDTASK_ERR_EID, CFE_EVS_EventType_ERROR,
"Recompute baseline of Memory Entry ID %d failed: child task in use", EntryID);
CS_AppData.HkPacket.Payload.CmdErrCounter++;
}
}

Reporter Info
Avi Weiss   @thnkslprpt

thnkslprpt added a commit to thnkslprpt/CS that referenced this issue Nov 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant