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_Enable/Disable/Get EntryID functions clean-up #111

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

CS_Enable/Disable/Get EntryID functions clean-up #111

thnkslprpt opened this issue Nov 30, 2024 · 0 comments · May be fixed by #112

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
CS_EnableEntryIDMemoryCmd, CS_DisableEntryIDMemoryCmd and CS_GetEntryIDMemoryCmd use some unnecessary intermediate variables and also use the wrong State variable in their debug event strings.

Code snips

CS/fsw/src/cs_memory_cmds.c

Lines 223 to 376 in f958cc0

void CS_EnableEntryIDMemoryCmd(const CS_EntryCmd_t *CmdPtr)
{
/* command verification variables */
CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
if (CS_CheckRecomputeOneshot() == false)
{
EntryID = CmdPtr->Payload.EntryID;
if ((EntryID < CS_MAX_NUM_MEMORY_TABLE_ENTRIES) &&
(CS_AppData.ResMemoryTblPtr[EntryID].State != CS_STATE_EMPTY))
{
ResultsEntry = &CS_AppData.ResMemoryTblPtr[EntryID];
ResultsEntry->State = CS_STATE_ENABLED;
CFE_EVS_SendEvent(CS_ENABLE_MEMORY_ENTRY_INF_EID, CFE_EVS_EventType_INFORMATION,
"Checksumming of Memory Entry ID %d is Enabled", EntryID);
if (CS_AppData.DefMemoryTblPtr[EntryID].State != CS_STATE_EMPTY)
{
CS_AppData.DefMemoryTblPtr[EntryID].State = CS_STATE_ENABLED;
CS_ResetTablesTblResultEntry(CS_AppData.MemResTablesTblPtr);
CFE_TBL_Modified(CS_AppData.DefMemoryTableHandle);
}
else
{
CFE_EVS_SendEvent(CS_ENABLE_MEMORY_DEF_EMPTY_DBG_EID, CFE_EVS_EventType_DEBUG,
"CS unable to update memory definition table for entry %d, State: %d", EntryID,
State);
}
CS_AppData.HkPacket.Payload.CmdCounter++;
}
else
{
if (EntryID >= CS_MAX_NUM_MEMORY_TABLE_ENTRIES)
{
State = CS_STATE_UNDEFINED;
}
else
{
State = CS_AppData.ResMemoryTblPtr[EntryID].State;
}
CFE_EVS_SendEvent(CS_ENABLE_MEMORY_INVALID_ENTRY_ERR_EID, CFE_EVS_EventType_ERROR,
"Enable Memory entry failed, invalid Entry ID: %d, State: %d, Max ID: %d", EntryID,
State, (CS_MAX_NUM_MEMORY_TABLE_ENTRIES - 1));
CS_AppData.HkPacket.Payload.CmdErrCounter++;
}
} /* end InProgress if */
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CS Disable a specific entry in the Memory table command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_DisableEntryIDMemoryCmd(const CS_EntryCmd_t *CmdPtr)
{
/* command verification variables */
CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
uint16 EntryID = 0;
uint16 State = CS_STATE_EMPTY;
if (CS_CheckRecomputeOneshot() == false)
{
EntryID = CmdPtr->Payload.EntryID;
if ((EntryID < CS_MAX_NUM_MEMORY_TABLE_ENTRIES) &&
(CS_AppData.ResMemoryTblPtr[EntryID].State != CS_STATE_EMPTY))
{
ResultsEntry = &CS_AppData.ResMemoryTblPtr[EntryID];
ResultsEntry->State = CS_STATE_DISABLED;
ResultsEntry->TempChecksumValue = 0;
ResultsEntry->ByteOffset = 0;
CFE_EVS_SendEvent(CS_DISABLE_MEMORY_ENTRY_INF_EID, CFE_EVS_EventType_INFORMATION,
"Checksumming of Memory Entry ID %d is Disabled", EntryID);
if (CS_AppData.DefMemoryTblPtr[EntryID].State != CS_STATE_EMPTY)
{
CS_AppData.DefMemoryTblPtr[EntryID].State = CS_STATE_DISABLED;
CS_ResetTablesTblResultEntry(CS_AppData.MemResTablesTblPtr);
CFE_TBL_Modified(CS_AppData.DefMemoryTableHandle);
}
else
{
CFE_EVS_SendEvent(CS_DISABLE_MEMORY_DEF_EMPTY_DBG_EID, CFE_EVS_EventType_DEBUG,
"CS unable to update memory definition table for entry %d, State: %d", EntryID,
State);
}
CS_AppData.HkPacket.Payload.CmdCounter++;
}
else
{
if (EntryID >= CS_MAX_NUM_MEMORY_TABLE_ENTRIES)
{
State = CS_STATE_UNDEFINED;
}
else
{
State = CS_AppData.ResMemoryTblPtr[EntryID].State;
}
CFE_EVS_SendEvent(CS_DISABLE_MEMORY_INVALID_ENTRY_ERR_EID, CFE_EVS_EventType_ERROR,
"Disable Memory entry failed, invalid Entry ID: %d, State: %d, Max ID: %d", EntryID,
State, (CS_MAX_NUM_MEMORY_TABLE_ENTRIES - 1));
CS_AppData.HkPacket.Payload.CmdErrCounter++;
}
} /* end InProgress if */
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* CS Retrieve an EntryID based on Address from Memory table cmd */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void CS_GetEntryIDMemoryCmd(const CS_GetEntryIDCmd_t *CmdPtr)
{
/* command verification variables */
CS_Res_EepromMemory_Table_Entry_t *StartOfResultsTable = NULL;
CS_Res_EepromMemory_Table_Entry_t *ResultsEntry = NULL;
uint16 Loop = 0;
bool EntryFound = false;
StartOfResultsTable = CS_AppData.ResMemoryTblPtr;
for (Loop = 0; Loop < CS_MAX_NUM_MEMORY_TABLE_ENTRIES; Loop++)
{
ResultsEntry = &StartOfResultsTable[Loop];
if ((ResultsEntry->StartAddress <= CmdPtr->Payload.Address) &&
CmdPtr->Payload.Address <= (ResultsEntry->StartAddress + ResultsEntry->NumBytesToChecksum) &&
ResultsEntry->State != CS_STATE_EMPTY)
{
CFE_EVS_SendEvent(CS_GET_ENTRY_ID_MEMORY_INF_EID, CFE_EVS_EventType_INFORMATION,
"Memory Found Address 0x%08X in Entry ID %d", (unsigned int)(CmdPtr->Payload.Address), Loop);
EntryFound = true;
}
}
if (EntryFound == false)
{
CFE_EVS_SendEvent(CS_GET_ENTRY_ID_MEMORY_NOT_FOUND_INF_EID, CFE_EVS_EventType_INFORMATION,
"Address 0x%08X was not found in Memory table", (unsigned int)(CmdPtr->Payload.Address));
}
CS_AppData.HkPacket.Payload.CmdCounter++;
}

Reporter Info
Avi Weiss   @thnkslprpt

thnkslprpt added a commit to thnkslprpt/CS that referenced this issue Nov 30, 2024
@thnkslprpt thnkslprpt linked a pull request Nov 30, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant