Skip to content

Commit 693cb5d

Browse files
author
Jacob Hageman
committed
Fix #1153, Remove logic based on LogEnabled status
1 parent f55cc82 commit 693cb5d

File tree

5 files changed

+184
-266
lines changed

5 files changed

+184
-266
lines changed

fsw/cfe-core/src/evs/cfe_evs_log.c

Lines changed: 100 additions & 124 deletions
Original file line numberDiff line numberDiff line change
@@ -54,53 +54,50 @@
5454
void EVS_AddLog (CFE_EVS_LongEventTlm_t *EVS_PktPtr)
5555
{
5656

57-
if (CFE_EVS_Global.EVS_TlmPkt.Payload.LogEnabled == true)
58-
{
59-
/* Serialize access to event log control variables */
60-
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
57+
/* Serialize access to event log control variables */
58+
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
6159

62-
if ((CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true) &&
63-
(CFE_EVS_Global.EVS_LogPtr->LogMode == CFE_EVS_LogMode_DISCARD))
60+
if ((CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true) &&
61+
(CFE_EVS_Global.EVS_LogPtr->LogMode == CFE_EVS_LogMode_DISCARD))
62+
{
63+
/* If log is full and in discard mode, just count the event */
64+
CFE_EVS_Global.EVS_LogPtr->LogOverflowCounter++;
65+
}
66+
else
67+
{
68+
if (CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true)
6469
{
65-
/* If log is full and in discard mode, just count the event */
70+
/* If log is full and in wrap mode, count it and store it */
6671
CFE_EVS_Global.EVS_LogPtr->LogOverflowCounter++;
6772
}
68-
else
69-
{
70-
if (CFE_EVS_Global.EVS_LogPtr->LogFullFlag == true)
71-
{
72-
/* If log is full and in wrap mode, count it and store it */
73-
CFE_EVS_Global.EVS_LogPtr->LogOverflowCounter++;
74-
}
7573

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

80-
CFE_EVS_Global.EVS_LogPtr->Next++;
78+
CFE_EVS_Global.EVS_LogPtr->Next++;
8179

82-
if (CFE_EVS_Global.EVS_LogPtr->Next >= CFE_PLATFORM_EVS_LOG_MAX)
83-
{
84-
/* This is important, even if we are in discard mode */
85-
CFE_EVS_Global.EVS_LogPtr->Next = 0;
86-
}
80+
if (CFE_EVS_Global.EVS_LogPtr->Next >= CFE_PLATFORM_EVS_LOG_MAX)
81+
{
82+
/* This is important, even if we are in discard mode */
83+
CFE_EVS_Global.EVS_LogPtr->Next = 0;
84+
}
8785

88-
/* Log count cannot exceed the number of entries in the log */
89-
if (CFE_EVS_Global.EVS_LogPtr->LogCount < CFE_PLATFORM_EVS_LOG_MAX)
90-
{
91-
CFE_EVS_Global.EVS_LogPtr->LogCount++;
86+
/* Log count cannot exceed the number of entries in the log */
87+
if (CFE_EVS_Global.EVS_LogPtr->LogCount < CFE_PLATFORM_EVS_LOG_MAX)
88+
{
89+
CFE_EVS_Global.EVS_LogPtr->LogCount++;
9290

93-
if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
94-
{
95-
/* The full flag and log count are somewhat redundant */
96-
CFE_EVS_Global.EVS_LogPtr->LogFullFlag = true;
97-
}
91+
if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
92+
{
93+
/* The full flag and log count are somewhat redundant */
94+
CFE_EVS_Global.EVS_LogPtr->LogFullFlag = true;
9895
}
9996
}
100-
101-
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
10297
}
10398

99+
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
100+
104101
return;
105102

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

162-
if (CFE_EVS_Global.EVS_TlmPkt.Payload.LogEnabled == false)
159+
/* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */
160+
CFE_SB_MessageStringGet(LogFilename, (const char *)CmdPtr->LogFilename, CFE_PLATFORM_EVS_DEFAULT_LOG_FILE,
161+
sizeof(LogFilename), sizeof(CmdPtr->LogFilename));
162+
163+
/* Create the log file */
164+
Result = OS_OpenCreate(&LogFileHandle, LogFilename, OS_FILE_FLAG_CREATE | OS_FILE_FLAG_TRUNCATE, OS_WRITE_ONLY);
165+
166+
if (Result < OS_SUCCESS)
163167
{
164-
EVS_SendEvent(CFE_EVS_NO_LOGWR_EID, CFE_EVS_EventType_ERROR,
165-
"Write Log Command: Event Log is Disabled");
166-
Result = CFE_EVS_FUNCTION_DISABLED;
168+
EVS_SendEvent(CFE_EVS_ERR_CRLOGFILE_EID, CFE_EVS_EventType_ERROR,
169+
"Write Log File Command Error: OS_OpenCreate = 0x%08X, filename = %s",
170+
(unsigned int)Result, LogFilename);
167171
}
168172
else
169173
{
170-
/* Copy the commanded filename into local buffer to ensure size limitation and to allow for modification */
171-
CFE_SB_MessageStringGet(LogFilename, (const char *)CmdPtr->LogFilename, CFE_PLATFORM_EVS_DEFAULT_LOG_FILE,
172-
sizeof(LogFilename), sizeof(CmdPtr->LogFilename));
174+
/* Result will be overridden if everything works */
175+
Result = CFE_EVS_FILE_WRITE_ERROR;
173176

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

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

183-
}
184-
else
183+
if (BytesWritten == sizeof(LogFileHdr))
185184
{
186-
/* Result will be overridden if everything works */
187-
Result = CFE_EVS_FILE_WRITE_ERROR;
188-
189-
/* Initialize cFE file header for an event log file */
190-
CFE_FS_InitHeader(&LogFileHdr, "cFE EVS Log File", CFE_FS_SubType_EVS_EVENTLOG);
191-
192-
/* Write the file header to the log file */
193-
BytesWritten = CFE_FS_WriteHeader(LogFileHandle, &LogFileHdr);
185+
/* Serialize access to event log control variables */
186+
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
194187

195-
if (BytesWritten == sizeof(LogFileHdr))
188+
/* Is the log full? -- Doesn't matter if wrap mode is enabled */
189+
if (CFE_EVS_Global.EVS_LogPtr->LogCount == CFE_PLATFORM_EVS_LOG_MAX)
190+
{
191+
/* Start with log entry that will be overwritten next (oldest) */
192+
LogIndex = CFE_EVS_Global.EVS_LogPtr->Next;
193+
}
194+
else
196195
{
197-
/* Serialize access to event log control variables */
198-
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
196+
/* Start with the first entry in the log (oldest) */
197+
LogIndex = 0;
198+
}
199199

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

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

219-
if (BytesWritten == sizeof(CFE_EVS_Global.EVS_LogPtr->LogEntry[LogIndex]))
211+
if (LogIndex >= CFE_PLATFORM_EVS_LOG_MAX)
220212
{
221-
LogIndex++;
222-
223-
if (LogIndex >= CFE_PLATFORM_EVS_LOG_MAX)
224-
{
225-
LogIndex = 0;
226-
}
227-
}
228-
else
229-
{
230-
break;
213+
LogIndex = 0;
231214
}
232215
}
233-
234-
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
235-
236-
/* Process command handler success result */
237-
if (i == CFE_EVS_Global.EVS_LogPtr->LogCount)
238-
{
239-
EVS_SendEvent(CFE_EVS_WRLOG_EID, CFE_EVS_EventType_DEBUG,
240-
"Write Log File Command: %d event log entries written to %s",
241-
(int)CFE_EVS_Global.EVS_LogPtr->LogCount, LogFilename);
242-
Result = CFE_SUCCESS;
243-
}
244216
else
245217
{
246-
EVS_SendEvent(CFE_EVS_ERR_WRLOGFILE_EID, CFE_EVS_EventType_ERROR,
247-
"Write Log File Command Error: OS_write = 0x%08X, filename = %s",
248-
(unsigned int)BytesWritten, LogFilename);
218+
break;
249219
}
250220
}
251221

252-
OS_close(LogFileHandle);
222+
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
223+
224+
/* Process command handler success result */
225+
if (i == CFE_EVS_Global.EVS_LogPtr->LogCount)
226+
{
227+
EVS_SendEvent(CFE_EVS_WRLOG_EID, CFE_EVS_EventType_DEBUG,
228+
"Write Log File Command: %d event log entries written to %s",
229+
(int)CFE_EVS_Global.EVS_LogPtr->LogCount, LogFilename);
230+
Result = CFE_SUCCESS;
231+
}
232+
else
233+
{
234+
EVS_SendEvent(CFE_EVS_ERR_WRLOGFILE_EID, CFE_EVS_EventType_ERROR,
235+
"Write Log File Command Error: OS_write = 0x%08X, filename = %s",
236+
(unsigned int)BytesWritten, LogFilename);
237+
}
253238
}
254239

240+
OS_close(LogFileHandle);
255241
}
256242

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

277-
if (CFE_EVS_Global.EVS_TlmPkt.Payload.LogEnabled == true)
263+
if ((CmdPtr->LogMode == CFE_EVS_LogMode_OVERWRITE) || (CmdPtr->LogMode == CFE_EVS_LogMode_DISCARD))
278264
{
279-
if ((CmdPtr->LogMode == CFE_EVS_LogMode_OVERWRITE) || (CmdPtr->LogMode == CFE_EVS_LogMode_DISCARD))
280-
{
281-
/* Serialize access to event log control variables */
282-
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
283-
CFE_EVS_Global.EVS_LogPtr->LogMode = CmdPtr->LogMode;
284-
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
265+
/* Serialize access to event log control variables */
266+
OS_MutSemTake(CFE_EVS_Global.EVS_SharedDataMutexID);
267+
CFE_EVS_Global.EVS_LogPtr->LogMode = CmdPtr->LogMode;
268+
OS_MutSemGive(CFE_EVS_Global.EVS_SharedDataMutexID);
285269

286-
EVS_SendEvent(CFE_EVS_LOGMODE_EID, CFE_EVS_EventType_DEBUG,
287-
"Set Log Mode Command: Log Mode = %d", (int)CmdPtr->LogMode);
270+
EVS_SendEvent(CFE_EVS_LOGMODE_EID, CFE_EVS_EventType_DEBUG,
271+
"Set Log Mode Command: Log Mode = %d", (int)CmdPtr->LogMode);
288272

289-
Status = CFE_SUCCESS;
290-
}
291-
else
292-
{
293-
Status = CFE_EVS_INVALID_PARAMETER;
294-
EVS_SendEvent(CFE_EVS_ERR_LOGMODE_EID, CFE_EVS_EventType_ERROR,
295-
"Set Log Mode Command Error: Log Mode = %d", (int)CmdPtr->LogMode);
296-
}
273+
Status = CFE_SUCCESS;
297274
}
298275
else
299276
{
300-
Status = CFE_EVS_FUNCTION_DISABLED;
301-
EVS_SendEvent(CFE_EVS_NO_LOGSET_EID, CFE_EVS_EventType_ERROR,
302-
"Set Log Mode Command: Event Log is Disabled");
277+
Status = CFE_EVS_INVALID_PARAMETER;
278+
EVS_SendEvent(CFE_EVS_ERR_LOGMODE_EID, CFE_EVS_EventType_ERROR,
279+
"Set Log Mode Command Error: Log Mode = %d", (int)CmdPtr->LogMode);
303280
}
304281

305-
306282
return Status;
307283

308284
} /* End CFE_EVS_SetLogModeCmd */

0 commit comments

Comments
 (0)