Skip to content

Commit 949e89a

Browse files
author
Gerardo E. Cruz-Ortiz
committed
Merge pull request #58 from ejtimmon/fix-issue-45
Fix #45, Refactor to implement command and utility functions in separate files
1 parent 155a3e7 commit 949e89a

File tree

12 files changed

+770
-276
lines changed

12 files changed

+770
-276
lines changed

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ include_directories(fsw/platform_inc)
99
include_directories(${sample_lib_MISSION_DIR}/fsw/public_inc)
1010

1111
# Create the app module
12-
add_cfe_app(sample_app fsw/src/sample_app.c)
12+
add_cfe_app(sample_app fsw/src/sample_app.c
13+
fsw/src/sample_app_cmds.c
14+
fsw/src/sample_app_utils.c)
1315

1416
# Add table
1517
add_cfe_tables(sampleTable fsw/src/sample_table.c)

fsw/src/sample_app.c

Lines changed: 32 additions & 193 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "sample_app_version.h"
3333
#include "sample_app.h"
3434
#include "sample_table.h"
35+
#include "sample_app_cmds.h"
36+
#include "sample_app_utils.h"
3537

3638
/* The sample_lib module provides the SAMPLE_Function() prototype */
3739
#include <string.h>
@@ -106,6 +108,13 @@ void SAMPLE_AppMain( void )
106108

107109
}
108110

111+
112+
CFE_EVS_SendEvent(SAMPLE_APP_EXIT_ERR_EID,
113+
CFE_EVS_EventType_ERROR,
114+
"SAMPLE_APP Terminating");
115+
116+
CFE_ES_WriteToSysLog("SAMPLE_APP Terminating.");
117+
109118
/*
110119
** Performance Log Exit Stamp
111120
*/
@@ -186,8 +195,10 @@ int32 SAMPLE_AppInit( void )
186195
SAMPLE_AppData.PipeName);
187196
if (status != CFE_SUCCESS)
188197
{
189-
CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n",
190-
(unsigned long)status);
198+
CFE_EVS_SendEvent(SAMPLE_APP_PIPE_CREATE_ERR_EID,
199+
CFE_EVS_EventType_ERROR,
200+
"Sample App: Error creating pipe, RC = 0x%08lX\n",
201+
(unsigned long)status);
191202
return ( status );
192203
}
193204

@@ -198,8 +209,10 @@ int32 SAMPLE_AppInit( void )
198209
SAMPLE_AppData.CommandPipe);
199210
if (status != CFE_SUCCESS)
200211
{
201-
CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n",
202-
(unsigned long)status);
212+
CFE_EVS_SendEvent(SAMPLE_APP_SUB_HK_ERR_EID,
213+
CFE_EVS_EventType_ERROR,
214+
"Sample App: Error Subscribing to HK request, RC = 0x%08lX\n",
215+
(unsigned long)status);
203216
return ( status );
204217
}
205218

@@ -210,8 +223,10 @@ int32 SAMPLE_AppInit( void )
210223
SAMPLE_AppData.CommandPipe);
211224
if (status != CFE_SUCCESS )
212225
{
213-
CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n",
214-
(unsigned long)status);
226+
CFE_EVS_SendEvent(SAMPLE_APP_SUB_CMD_ERR_EID,
227+
CFE_EVS_EventType_ERROR,
228+
"Sample App: Error Subscribing to Command, RC = 0x%08lX\n",
229+
(unsigned long)status);
215230

216231
return ( status );
217232
}
@@ -226,8 +241,10 @@ int32 SAMPLE_AppInit( void )
226241
SAMPLE_TblValidationFunc);
227242
if ( status != CFE_SUCCESS )
228243
{
229-
CFE_ES_WriteToSysLog("Sample App: Error Registering \
230-
Table, RC = 0x%08lX\n", (unsigned long)status);
244+
CFE_EVS_SendEvent(SAMPLE_APP_TBL_REG_ERR_EID,
245+
CFE_EVS_EventType_ERROR,
246+
"Sample App: Error Registering Table, RC = 0x%08lX\n",
247+
(unsigned long)status);
231248

232249
return ( status );
233250
}
@@ -277,7 +294,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
277294
default:
278295
CFE_EVS_SendEvent(SAMPLE_INVALID_MSGID_ERR_EID,
279296
CFE_EVS_EventType_ERROR,
280-
"SAMPLE: invalid command packet,MID = 0x%x",
297+
"SAMPLE: invalid command packet,MID = 0x%x",
281298
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
282299
break;
283300
}
@@ -294,7 +311,6 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
294311
void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
295312
{
296313
uint16 CommandCode;
297-
298314
CommandCode = CFE_SB_GetCmdCode(Msg);
299315

300316
/*
@@ -303,27 +319,24 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
303319
switch (CommandCode)
304320
{
305321
case SAMPLE_APP_NOOP_CC:
306-
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
307-
{
322+
if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
323+
{
308324
SAMPLE_Noop((SAMPLE_Noop_t *)Msg);
309325
}
310-
311326
break;
312327

313328
case SAMPLE_APP_RESET_COUNTERS_CC:
314-
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t)))
315-
{
329+
if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t)))
330+
{
316331
SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg);
317332
}
318-
319333
break;
320334

321335
case SAMPLE_APP_PROCESS_CC:
322-
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t)))
323-
{
336+
if(SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t)))
337+
{
324338
SAMPLE_Process((SAMPLE_Process_t *)Msg);
325339
}
326-
327340
break;
328341

329342
/* default case already found during FC vs length test */
@@ -376,179 +389,5 @@ int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )
376389

377390
} /* End of SAMPLE_ReportHousekeeping() */
378391

379-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
380-
/* */
381-
/* SAMPLE_Noop -- SAMPLE NOOP commands */
382-
/* */
383-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
384-
int32 SAMPLE_Noop( const SAMPLE_Noop_t *Msg )
385-
{
386-
387-
SAMPLE_AppData.CmdCounter++;
388-
389-
CFE_EVS_SendEvent(SAMPLE_COMMANDNOP_INF_EID,
390-
CFE_EVS_EventType_INFORMATION,
391-
"SAMPLE: NOOP command Version %d.%d.%d.%d",
392-
SAMPLE_APP_MAJOR_VERSION,
393-
SAMPLE_APP_MINOR_VERSION,
394-
SAMPLE_APP_REVISION,
395-
SAMPLE_APP_MISSION_REV);
396-
397-
return CFE_SUCCESS;
398-
399-
} /* End of SAMPLE_Noop */
400-
401-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
402-
/* Name: SAMPLE_ResetCounters */
403-
/* */
404-
/* Purpose: */
405-
/* This function resets all the global counter variables that are */
406-
/* part of the task telemetry. */
407-
/* */
408-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
409-
int32 SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg )
410-
{
411-
412-
SAMPLE_AppData.CmdCounter = 0;
413-
SAMPLE_AppData.ErrCounter = 0;
414-
415-
CFE_EVS_SendEvent(SAMPLE_COMMANDRST_INF_EID,
416-
CFE_EVS_EventType_INFORMATION,
417-
"SAMPLE: RESET command");
418-
419-
return CFE_SUCCESS;
420-
421-
} /* End of SAMPLE_ResetCounters() */
422-
423-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
424-
/* Name: SAMPLE_Process */
425-
/* */
426-
/* Purpose: */
427-
/* This function Process Ground Station Command */
428-
/* */
429-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
430-
int32 SAMPLE_Process( const SAMPLE_Process_t *Msg )
431-
{
432-
int32 status;
433-
SAMPLE_Table_t *TblPtr;
434-
const char *TableName = "SAMPLE_APP.SampleTable";
435-
436-
/* Sample Use of Table */
437-
438-
status = CFE_TBL_GetAddress((void *)&TblPtr,
439-
SAMPLE_AppData.TblHandles[0]);
440-
441-
if (status != CFE_SUCCESS)
442-
{
443-
CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx",
444-
(unsigned long)status);
445-
return status;
446-
}
447-
448-
CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d",
449-
TblPtr->Int1,
450-
TblPtr->Int2);
451-
452-
SAMPLE_GetCrc(TableName);
453-
454-
status = CFE_TBL_ReleaseAddress(SAMPLE_AppData.TblHandles[0]);
455-
if (status != CFE_SUCCESS)
456-
{
457-
CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx",
458-
(unsigned long)status);
459-
return status;
460-
}
461-
462-
/* Invoke a function provided by SAMPLE_LIB */
463-
SAMPLE_Function();
464-
465-
return CFE_SUCCESS;
466-
467-
} /* End of SAMPLE_ProcessCC */
468-
469-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
470-
/* */
471-
/* SAMPLE_VerifyCmdLength() -- Verify command packet length */
472-
/* */
473-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
474-
bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength )
475-
{
476-
bool result = true;
477-
478-
uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg);
479-
480-
/*
481-
** Verify the command packet length.
482-
*/
483-
if (ExpectedLength != ActualLength)
484-
{
485-
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(Msg);
486-
uint16 CommandCode = CFE_SB_GetCmdCode(Msg);
487-
488-
CFE_EVS_SendEvent(SAMPLE_LEN_ERR_EID,
489-
CFE_EVS_EventType_ERROR,
490-
"Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d",
491-
(unsigned int)CFE_SB_MsgIdToValue(MessageID),
492-
CommandCode,
493-
ActualLength,
494-
ExpectedLength);
495392

496-
result = false;
497-
498-
SAMPLE_AppData.ErrCounter++;
499-
}
500-
501-
return( result );
502-
503-
} /* End of SAMPLE_VerifyCmdLength() */
504-
505-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
506-
/* */
507-
/* SAMPLE_TblValidationFunc -- Verify contents of First Table */
508-
/* buffer contents */
509-
/* */
510-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
511-
int32 SAMPLE_TblValidationFunc( void *TblData )
512-
{
513-
int32 ReturnCode = CFE_SUCCESS;
514-
SAMPLE_Table_t *TblDataPtr = (SAMPLE_Table_t *)TblData;
515-
516-
/*
517-
** Sample Table Validation
518-
*/
519-
if (TblDataPtr->Int1 > SAMPLE_TBL_ELEMENT_1_MAX)
520-
{
521-
/* First element is out of range, return an appropriate error code */
522-
ReturnCode = SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE;
523-
}
524-
525-
return ReturnCode;
526-
527-
} /* End of Sample_TblValidationFunc*/
528-
529-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
530-
/* */
531-
/* SAMPLE_GetCrc -- Output CRC */
532-
/* */
533-
/* */
534-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
535-
void SAMPLE_GetCrc( const char *TableName )
536-
{
537-
int32 status;
538-
uint32 Crc;
539-
CFE_TBL_Info_t TblInfoPtr;
540-
541-
status = CFE_TBL_GetInfo(&TblInfoPtr, TableName);
542-
if (status != CFE_SUCCESS)
543-
{
544-
CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info");
545-
}
546-
else
547-
{
548-
Crc = TblInfoPtr.Crc;
549-
CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)Crc);
550-
}
551-
552-
return;
553393

554-
} /* End of SAMPLE_GetCrc */

fsw/src/sample_app.h

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#include "sample_app_perfids.h"
4242
#include "sample_app_msgids.h"
4343
#include "sample_app_msg.h"
44+
#include "sample_app_cmds.h"
45+
#include "sample_app_utils.h"
4446

4547
/***********************************************************************/
4648
#define SAMPLE_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */
@@ -53,6 +55,7 @@
5355
#define SAMPLE_TABLE_OUT_OF_RANGE_ERR_CODE -1
5456

5557
#define SAMPLE_TBL_ELEMENT_1_MAX 10
58+
5659
/************************************************************************
5760
** Type Definitions
5861
*************************************************************************/
@@ -105,6 +108,8 @@ typedef struct
105108

106109
} SAMPLE_AppData_t;
107110

111+
extern SAMPLE_AppData_t SAMPLE_AppData;
112+
108113
/****************************************************************************/
109114
/*
110115
** Local function prototypes.
@@ -117,13 +122,5 @@ int32 SAMPLE_AppInit(void);
117122
void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg);
118123
void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg);
119124
int32 SAMPLE_ReportHousekeeping(const CCSDS_CommandPacket_t *Msg);
120-
int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg);
121-
int32 SAMPLE_Process(const SAMPLE_Process_t *Msg);
122-
int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg);
123-
void SAMPLE_GetCrc(const char *TableName);
124-
125-
int32 SAMPLE_TblValidationFunc(void *TblData);
126-
127-
bool SAMPLE_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength);
128125

129126
#endif /* _sample_app_h_ */

0 commit comments

Comments
 (0)