Skip to content

Commit

Permalink
Fix #1153, Remove logic based on LogEnabled status
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Mar 3, 2021
1 parent f55cc82 commit 693cb5d
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 266 deletions.
224 changes: 100 additions & 124 deletions fsw/cfe-core/src/evs/cfe_evs_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,53 +54,50 @@
void EVS_AddLog (CFE_EVS_LongEventTlm_t *EVS_PktPtr)
{

if (CFE_EVS_Global.EVS_TlmPkt.Payload.LogEnabled == true)
{
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);

if ((CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true) &&
(CFE_EVS_Global.EVS_LogPtr->LogMode == CFE_EVS_LogMode_DISCARD))
if ((CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true) &&
(CFE_EVS_Global.EVS_LogPtr->LogMode == CFE_EVS_LogMode_DISCARD))
{
/* If log is full and in discard mode, just count the event */
CFE_EVS_Global.EVS_LogPtr->LogOverflowCounter++;
}
else
{
if (CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true)
{
/* If log is full and in discard mode, just count the event */
/* If log is full and in wrap mode, count it and store it */
CFE_EVS_Global.EVS_LogPtr->LogOverflowCounter++;
}
else
{
if (CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true)
{
/* If log is full and in wrap mode, count it and store it */
CFE_EVS_Global.EVS_LogPtr->LogOverflowCounter++;
}

/* Copy the event data to the next available entry in the log */
memcpy(&CFE_EVS_Global.EVS_LogPtr->LogEntry[CFE_EVS_Global.EVS_LogPtr->Next],
EVS_PktPtr, sizeof(*EVS_PktPtr));
/* Copy the event data to the next available entry in the log */
memcpy(&CFE_EVS_Global.EVS_LogPtr->LogEntry[CFE_EVS_Global.EVS_LogPtr->Next],
EVS_PktPtr, sizeof(*EVS_PktPtr));

CFE_EVS_Global.EVS_LogPtr->Next++;
CFE_EVS_Global.EVS_LogPtr->Next++;

if (CFE_EVS_Global.EVS_LogPtr->Next >= CFE_PLATFORM_EVS_LOG_MAX)
{
/* This is important, even if we are in discard mode */
CFE_EVS_Global.EVS_LogPtr->Next = 0;
}
if (CFE_EVS_Global.EVS_LogPtr->Next >= CFE_PLATFORM_EVS_LOG_MAX)
{
/* This is important, even if we are in discard mode */
CFE_EVS_Global.EVS_LogPtr->Next = 0;
}

/* Log count cannot exceed the number of entries in the log */
if (CFE_EVS_Global.EVS_LogPtr->LogCount < CFE_PLATFORM_EVS_LOG_MAX)
{
CFE_EVS_Global.EVS_LogPtr->LogCount++;
/* Log count cannot exceed the number of entries in the log */
if (CFE_EVS_Global.EVS_LogPtr->LogCount < CFE_PLATFORM_EVS_LOG_MAX)
{
CFE_EVS_Global.EVS_LogPtr->LogCount++;

if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
{
/* The full flag and log count are somewhat redundant */
CFE_EVS_Global.EVS_LogPtr->LogFullFlag = true;
}
if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
{
/* The full flag and log count are somewhat redundant */
CFE_EVS_Global.EVS_LogPtr->LogFullFlag = true;
}
}

OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
}

OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);

return;

} /* End EVS_AddLog */
Expand Down Expand Up @@ -159,99 +156,88 @@ int32 CFE_EVS_WriteLogDataFileCmd(const CFE_EVS_WriteLogDataFileCmd_t *data)
CFE_FS_Header_t LogFileHdr;
char LogFilename[OS_MAX_PATH_LEN];

if (CFE_EVS_Global.EVS_TlmPkt.Payload.LogEnabled == false)
/* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */
CFE_SB_MessageStringGet(LogFilename, (const char *)CmdPtr->LogFilename, CFE_PLATFORM_EVS_DEFAULT_LOG_FILE,
sizeof(LogFilename), sizeof(CmdPtr->LogFilename));

/* Create the log file */
Result = OS_OpenCreate(&LogFileHandle, LogFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);

if (Result < OS_SUCCESS)
{
EVS_SendEvent(CFE_EVS_NO_LOGWR_EID, CFE_EVS_EventType_ERROR,
"Write Log Command: Event Log is Disabled");
Result = CFE_EVS_FUNCTION_DISABLED;
EVS_SendEvent(CFE_EVS_ERR_CRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_OpenCreate = 0x%08X, filename = %s",
(unsigned int)Result, LogFilename);
}
else
{
/* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */
CFE_SB_MessageStringGet(LogFilename, (const char *)CmdPtr->LogFilename, CFE_PLATFORM_EVS_DEFAULT_LOG_FILE,
sizeof(LogFilename), sizeof(CmdPtr->LogFilename));
/* Result will be overridden if everything works */
Result = CFE_EVS_FILE_WRITE_ERROR;

/* Create the log file */
Result = OS_OpenCreate(&LogFileHandle, LogFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
/* Initialize cFE file header for an event log file */
CFE_FS_InitHeader(&LogFileHdr, "cFE EVS Log File", CFE_FS_SubType_EVS_EVENTLOG);

if (Result < OS_SUCCESS)
{
EVS_SendEvent(CFE_EVS_ERR_CRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_OpenCreate = 0x%08X, filename = %s",
(unsigned int)Result, LogFilename);
/* Write the file header to the log file */
BytesWritten = CFE_FS_WriteHeader(LogFileHandle, &LogFileHdr);

}
else
if (BytesWritten == sizeof(LogFileHdr))
{
/* Result will be overridden if everything works */
Result = CFE_EVS_FILE_WRITE_ERROR;

/* Initialize cFE file header for an event log file */
CFE_FS_InitHeader(&LogFileHdr, "cFE EVS Log File", CFE_FS_SubType_EVS_EVENTLOG);

/* Write the file header to the log file */
BytesWritten = CFE_FS_WriteHeader(LogFileHandle, &LogFileHdr);
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);

if (BytesWritten == sizeof(LogFileHdr))
/* Is the log full? -- Doesn't matter if wrap mode is enabled */
if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
{
/* Start with log entry that will be overwritten next (oldest) */
LogIndex = CFE_EVS_Global.EVS_LogPtr->Next;
}
else
{
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
/* Start with the first entry in the log (oldest) */
LogIndex = 0;
}

/* Is the log full? -- Doesn't matter if wrap mode is enabled */
if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
{
/* Start with log entry that will be overwritten next (oldest) */
LogIndex = CFE_EVS_Global.EVS_LogPtr->Next;
}
else
{
/* Start with the first entry in the log (oldest) */
LogIndex = 0;
}
/* Write all the "in-use" event log entries to the file */
for (i = 0; i < CFE_EVS_Global.EVS_LogPtr->LogCount; i++)
{
BytesWritten = OS_write(LogFileHandle,
&CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex],
sizeof(CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex]));

/* Write all the "in-use" event log entries to the file */
for (i = 0; i < CFE_EVS_Global.EVS_LogPtr->LogCount; i++)
if (BytesWritten == sizeof(CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex]))
{
BytesWritten = OS_write(LogFileHandle,
&CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex],
sizeof(CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex]));
LogIndex++;

if (BytesWritten == sizeof(CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex]))
if (LogIndex >= CFE_PLATFORM_EVS_LOG_MAX)
{
LogIndex++;

if (LogIndex >= CFE_PLATFORM_EVS_LOG_MAX)
{
LogIndex = 0;
}
}
else
{
break;
LogIndex = 0;
}
}

OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);

/* Process command handler success result */
if (i == CFE_EVS_Global.EVS_LogPtr->LogCount)
{
EVS_SendEvent(CFE_EVS_WRLOG_EID, CFE_EVS_EventType_DEBUG,
"Write Log File Command: %d event log entries written to %s",
(int)CFE_EVS_Global.EVS_LogPtr->LogCount, LogFilename);
Result = CFE_SUCCESS;
}
else
{
EVS_SendEvent(CFE_EVS_ERR_WRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_write = 0x%08X, filename = %s",
(unsigned int)BytesWritten, LogFilename);
break;
}
}

OS_close(LogFileHandle);
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);

/* Process command handler success result */
if (i == CFE_EVS_Global.EVS_LogPtr->LogCount)
{
EVS_SendEvent(CFE_EVS_WRLOG_EID, CFE_EVS_EventType_DEBUG,
"Write Log File Command: %d event log entries written to %s",
(int)CFE_EVS_Global.EVS_LogPtr->LogCount, LogFilename);
Result = CFE_SUCCESS;
}
else
{
EVS_SendEvent(CFE_EVS_ERR_WRLOGFILE_EID, CFE_EVS_EventType_ERROR,
"Write Log File Command Error: OS_write = 0x%08X, filename = %s",
(unsigned int)BytesWritten, LogFilename);
}
}

OS_close(LogFileHandle);
}

return(Result);
Expand All @@ -274,35 +260,25 @@ int32 CFE_EVS_SetLogModeCmd(const CFE_EVS_SetLogModeCmd_t *data)
const CFE_EVS_SetLogMode_Payload_t *CmdPtr = &data->Payload;
int32 Status;

if (CFE_EVS_Global.EVS_TlmPkt.Payload.LogEnabled == true)
if ((CmdPtr->LogMode == CFE_EVS_LogMode_OVERWRITE) || (CmdPtr->LogMode == CFE_EVS_LogMode_DISCARD))
{
if ((CmdPtr->LogMode == CFE_EVS_LogMode_OVERWRITE) || (CmdPtr->LogMode == CFE_EVS_LogMode_DISCARD))
{
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
CFE_EVS_Global.EVS_LogPtr->LogMode = CmdPtr->LogMode;
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
/* Serialize access to event log control variables */
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
CFE_EVS_Global.EVS_LogPtr->LogMode = CmdPtr->LogMode;
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);

EVS_SendEvent(CFE_EVS_LOGMODE_EID, CFE_EVS_EventType_DEBUG,
"Set Log Mode Command: Log Mode = %d", (int)CmdPtr->LogMode);
EVS_SendEvent(CFE_EVS_LOGMODE_EID, CFE_EVS_EventType_DEBUG,
"Set Log Mode Command: Log Mode = %d", (int)CmdPtr->LogMode);

Status = CFE_SUCCESS;
}
else
{
Status = CFE_EVS_INVALID_PARAMETER;
EVS_SendEvent(CFE_EVS_ERR_LOGMODE_EID, CFE_EVS_EventType_ERROR,
"Set Log Mode Command Error: Log Mode = %d", (int)CmdPtr->LogMode);
}
Status = CFE_SUCCESS;
}
else
{
Status = CFE_EVS_FUNCTION_DISABLED;
EVS_SendEvent(CFE_EVS_NO_LOGSET_EID, CFE_EVS_EventType_ERROR,
"Set Log Mode Command: Event Log is Disabled");
Status = CFE_EVS_INVALID_PARAMETER;
EVS_SendEvent(CFE_EVS_ERR_LOGMODE_EID, CFE_EVS_EventType_ERROR,
"Set Log Mode Command Error: Log Mode = %d", (int)CmdPtr->LogMode);
}


return Status;

} /* End CFE_EVS_SetLogModeCmd */
Expand Down
Loading

0 comments on commit 693cb5d

Please sign in to comment.