forked from nasa/FM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfm_app.c
More file actions
430 lines (358 loc) · 14.6 KB
/
fm_app.c
File metadata and controls
430 lines (358 loc) · 14.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/************************************************************************
* NASA Docket No. GSC-18,918-1, and identified as “Core Flight
* Software System (cFS) File Manager Application Version 2.6.1”
*
* Copyright (c) 2021 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License. You may obtain
* a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
************************************************************************/
/**
* @file
* Core Flight System (CFS) File Manager (FM) Application
*
* The File Manager (FM) Application provides onboard file system
* management services by processing commands for copying and moving
* files, decompressing files, concatenating files, creating directories,
* deleting files and directories, and providing file and directory status.
* When the File Manager application receives a housekeeping request
* (scheduled within the scheduler application), FM reports it's housekeeping
* status values via telemetry messaging.
*/
#include "cfe.h"
#include "fm_msg.h"
#include "fm_msgdefs.h"
#include "fm_msgids.h"
#include "fm_app.h"
#include "fm_tbl.h"
#include "fm_child.h"
#include "fm_cmds.h"
#include "fm_cmd_utils.h"
#include "fm_events.h"
#include "fm_perfids.h"
#include "fm_platform_cfg.h"
#include "fm_version.h"
#include "fm_verify.h"
#include <string.h>
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM application global data */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
FM_GlobalData_t FM_GlobalData;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM application -- entry point and main loop processor */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FM_AppMain(void)
{
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
CFE_SB_Buffer_t *BufPtr = NULL;
int32 Result = CFE_SUCCESS;
/* Performance Log (start time counter) */
CFE_ES_PerfLogEntry(FM_APPMAIN_PERF_ID);
/*
** Perform application specific initialization...
*/
Result = FM_AppInit();
/*
** Check for start-up error...
*/
if (Result != CFE_SUCCESS)
{
/*
** Set request to terminate main loop...
*/
RunStatus = CFE_ES_RunStatus_APP_ERROR;
}
/*
** Main process loop...
*/
while (CFE_ES_RunLoop(&RunStatus) == true)
{
/* Performance Log (stop time counter) */
CFE_ES_PerfLogExit(FM_APPMAIN_PERF_ID);
/* Wait for the next Software Bus message */
Result = CFE_SB_ReceiveBuffer(&BufPtr, FM_GlobalData.CmdPipe, FM_SB_TIMEOUT);
/* Performance Log (start time counter) */
CFE_ES_PerfLogEntry(FM_APPMAIN_PERF_ID);
if (Result == CFE_SUCCESS)
{
if (BufPtr != NULL)
{
/* Process Software Bus message */
FM_ProcessPkt(BufPtr);
}
else
{
/* Software Bus thought it succeeded but provided a bad pointer */
CFE_EVS_SendEvent(FM_SB_RECEIVE_NULL_PTR_ERR_EID, CFE_EVS_EventType_ERROR,
"Main loop error: SB returned NULL pointer on success");
/* Set request to terminate main loop */
RunStatus = CFE_ES_RunStatus_APP_ERROR;
}
}
else if (Result == CFE_SB_TIME_OUT)
{
/* Allow cFE the chance to manage tables. This is typically done
* during the housekeeping cycle, but if housekeeping is done at
* less than a 1Hz rate the table management is done here as well. */
FM_ReleaseTablePointers();
FM_AcquireTablePointers();
}
else
{
/* Process Software Bus error */
CFE_EVS_SendEvent(FM_SB_RECEIVE_ERR_EID, CFE_EVS_EventType_ERROR,
"Main loop error: SB receive: result = 0x%08X", (unsigned int)Result);
/* Set request to terminate main loop */
RunStatus = CFE_ES_RunStatus_APP_ERROR;
}
}
/*
** Send an event describing the reason for the termination...
*/
CFE_EVS_SendEvent(FM_EXIT_ERR_EID, CFE_EVS_EventType_ERROR, "Application terminating: result = 0x%08X",
(unsigned int)Result);
/*
** In case cFE Event Services is not working...
*/
CFE_ES_WriteToSysLog("FM application terminating: result = 0x%08X\n", (unsigned int)Result);
/*
** Performance Log (stop time counter)...
*/
CFE_ES_PerfLogExit(FM_APPMAIN_PERF_ID);
/*
** Let cFE kill the task (and any child tasks)...
*/
CFE_ES_ExitApp(RunStatus);
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM application -- startup initialization processor */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 FM_AppInit(void)
{
const char *ErrText = "Initialization error:";
int32 Result = CFE_SUCCESS;
/* Initialize global data */
memset(&FM_GlobalData, 0, sizeof(FM_GlobalData));
/* Register for event services */
Result = CFE_EVS_Register(NULL, 0, CFE_EVS_EventFilter_BINARY);
if (Result != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("FM App: Error registering for Event Services, RC = 0x%08X\n", (unsigned int)Result);
}
else
{
/* Create Software Bus message pipe */
Result = CFE_SB_CreatePipe(&FM_GlobalData.CmdPipe, FM_APP_PIPE_DEPTH, FM_APP_PIPE_NAME);
if (Result != CFE_SUCCESS)
{
CFE_EVS_SendEvent(FM_STARTUP_CREAT_PIPE_ERR_EID, CFE_EVS_EventType_ERROR,
"%s create SB input pipe: result = 0x%08X", ErrText, (unsigned int)Result);
}
else
{
/* Subscribe to Housekeeping request commands */
Result = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(FM_SEND_HK_MID), FM_GlobalData.CmdPipe);
if (Result != CFE_SUCCESS)
{
CFE_EVS_SendEvent(FM_STARTUP_SUBSCRIB_HK_ERR_EID, CFE_EVS_EventType_ERROR,
"%s subscribe to HK request: result = 0x%08X", ErrText, (unsigned int)Result);
}
}
}
/* Keep indentation from getting too deep */
if (Result == CFE_SUCCESS)
{
/* Subscribe to FM ground command packets */
Result = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(FM_CMD_MID), FM_GlobalData.CmdPipe);
if (Result != CFE_SUCCESS)
{
CFE_EVS_SendEvent(FM_STARTUP_SUBSCRIB_GCMD_ERR_EID, CFE_EVS_EventType_ERROR,
"%s subscribe to FM commands: result = 0x%08X", ErrText, (unsigned int)Result);
}
else
{
/* Initialize FM tables */
Result = FM_TableInit();
if (Result != CFE_SUCCESS)
{
CFE_EVS_SendEvent(FM_STARTUP_TABLE_INIT_ERR_EID, CFE_EVS_EventType_ERROR,
"%s register free space table: result = 0x%08X", ErrText, (unsigned int)Result);
}
else
{
/* Create low priority child task */
FM_ChildInit();
/* Application startup event message */
CFE_EVS_SendEvent(FM_STARTUP_EID, CFE_EVS_EventType_INFORMATION,
"Initialization complete: version %d.%d.%d.%d", FM_MAJOR_VERSION, FM_MINOR_VERSION,
FM_REVISION, FM_MISSION_REV);
}
}
}
FM_CompressionService_Init();
return Result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM application -- input packet processor */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FM_ProcessPkt(const CFE_SB_Buffer_t *BufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID);
switch (CFE_SB_MsgIdToValue(MessageID))
{
/* Housekeeping request */
case FM_SEND_HK_MID:
FM_SendHkCmd(BufPtr);
break;
/* FM ground commands */
case FM_CMD_MID:
FM_ProcessCmd(BufPtr);
break;
default:
CFE_EVS_SendEvent(FM_MID_ERR_EID, CFE_EVS_EventType_ERROR,
"Main loop error: invalid message ID: mid = 0x%08lX",
(unsigned long)CFE_SB_MsgIdToValue(MessageID));
break;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM application -- command packet processor */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FM_ProcessCmd(const CFE_SB_Buffer_t *BufPtr)
{
bool Result = true;
CFE_MSG_FcnCode_t CommandCode = 0;
CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode);
/* Invoke specific command handler */
switch (CommandCode)
{
case FM_NOOP_CC:
Result = FM_NoopCmd(BufPtr);
break;
case FM_RESET_COUNTERS_CC:
Result = FM_ResetCountersCmd(BufPtr);
break;
case FM_COPY_FILE_CC:
Result = FM_CopyFileCmd(BufPtr);
break;
case FM_MOVE_FILE_CC:
Result = FM_MoveFileCmd(BufPtr);
break;
case FM_RENAME_FILE_CC:
Result = FM_RenameFileCmd(BufPtr);
break;
case FM_DELETE_FILE_CC:
Result = FM_DeleteFileCmd(BufPtr);
break;
case FM_DELETE_ALL_FILES_CC:
Result = FM_DeleteAllFilesCmd(BufPtr);
break;
case FM_DECOMPRESS_FILE_CC:
Result = FM_DecompressFileCmd(BufPtr);
break;
case FM_CONCAT_FILES_CC:
Result = FM_ConcatFilesCmd(BufPtr);
break;
case FM_GET_FILE_INFO_CC:
Result = FM_GetFileInfoCmd(BufPtr);
break;
case FM_GET_OPEN_FILES_CC:
Result = FM_GetOpenFilesCmd(BufPtr);
break;
case FM_CREATE_DIRECTORY_CC:
Result = FM_CreateDirectoryCmd(BufPtr);
break;
case FM_DELETE_DIRECTORY_CC:
Result = FM_DeleteDirectoryCmd(BufPtr);
break;
case FM_GET_DIR_LIST_FILE_CC:
Result = FM_GetDirListFileCmd(BufPtr);
break;
case FM_GET_DIR_LIST_PKT_CC:
Result = FM_GetDirListPktCmd(BufPtr);
break;
case FM_MONITOR_FILESYSTEM_SPACE_CC:
Result = FM_MonitorFilesystemSpaceCmd(BufPtr);
break;
case FM_SET_TABLE_STATE_CC:
Result = FM_SetTableStateCmd(BufPtr);
break;
case FM_SET_PERMISSIONS_CC:
Result = FM_SetPermissionsCmd(BufPtr);
break;
default:
Result = false;
CFE_EVS_SendEvent(FM_CC_ERR_EID, CFE_EVS_EventType_ERROR, "Main loop error: invalid command code: cc = %d",
CommandCode);
break;
}
if (Result == true)
{
/* Increment command success counter */
if (CommandCode != FM_RESET_COUNTERS_CC)
{
FM_GlobalData.CommandCounter++;
}
}
else
{
/* Increment command error counter */
FM_GlobalData.CommandErrCounter++;
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* FM application -- housekeeping request packet processor */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void FM_SendHkCmd(const CFE_SB_Buffer_t *BufPtr)
{
const char * CmdText = "HK Request";
bool Result = true;
FM_HousekeepingPkt_Payload_t *PayloadPtr;
/* Verify command packet length */
Result = FM_IsValidCmdPktLength(CFE_MSG_PTR(*BufPtr), sizeof(FM_SendHkCmd_t), FM_HK_REQ_ERR_EID, CmdText);
if (Result == true)
{
FM_ReleaseTablePointers();
FM_AcquireTablePointers();
/* Initialize housekeeping telemetry message */
CFE_MSG_Init(CFE_MSG_PTR(FM_GlobalData.HousekeepingPkt.TelemetryHeader), CFE_SB_ValueToMsgId(FM_HK_TLM_MID),
sizeof(FM_HousekeepingPkt_t));
PayloadPtr = &FM_GlobalData.HousekeepingPkt.Payload;
/* Report application command counters */
PayloadPtr->CommandCounter = FM_GlobalData.CommandCounter;
PayloadPtr->CommandErrCounter = FM_GlobalData.CommandErrCounter;
PayloadPtr->NumOpenFiles = FM_GetOpenFilesData(NULL);
/* Report child task command counters */
PayloadPtr->ChildCmdCounter = FM_GlobalData.ChildCmdCounter;
PayloadPtr->ChildCmdErrCounter = FM_GlobalData.ChildCmdErrCounter;
PayloadPtr->ChildCmdWarnCounter = FM_GlobalData.ChildCmdWarnCounter;
PayloadPtr->ChildQueueCount = FM_GlobalData.ChildQueueCount;
/* Report current and previous commands executed by the child task */
PayloadPtr->ChildCurrentCC = FM_GlobalData.ChildCurrentCC;
PayloadPtr->ChildPreviousCC = FM_GlobalData.ChildPreviousCC;
CFE_SB_TimeStampMsg(CFE_MSG_PTR(FM_GlobalData.HousekeepingPkt.TelemetryHeader));
CFE_SB_TransmitMsg(CFE_MSG_PTR(FM_GlobalData.HousekeepingPkt.TelemetryHeader), true);
}
}