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

Fix #210, Fix #211, bring sample_app fully into compliance #212

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
project(CFE_SAMPLE_APP C)

set(APP_SRC_FILES
fsw/src/sample_app.c
fsw/src/sample_app_cmds.c
fsw/src/sample_app_dispatch.c
fsw/src/sample_app_utils.c
)

# Create the app module
add_cfe_app(sample_app fsw/src/sample_app.c
fsw/src/sample_app_cmds.c
fsw/src/sample_app_utils.c)
add_cfe_app(sample_app ${APP_SRC_FILES})

target_include_directories(sample_app PUBLIC fsw/inc)
# Include the public API from sample_lib to demonstrate how
Expand Down
1 change: 1 addition & 0 deletions config/default_sample_app_fcncodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
#define SAMPLE_APP_NOOP_CC 0
#define SAMPLE_APP_RESET_COUNTERS_CC 1
#define SAMPLE_APP_PROCESS_CC 2
#define SAMPLE_APP_DISPLAY_PARAM_CC 3

#endif
44 changes: 44 additions & 0 deletions config/default_sample_app_interface_cfg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/************************************************************************
* NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes”
*
* Copyright (c) 2020 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:https://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
* SAMPLE_APP Application Public Definitions
*
* This provides default values for configurable items that affect
* the interface(s) of this module. This includes the CMD/TLM message
* interface, tables definitions, and any other data products that
* serve to exchange information with other entities.
*
* @note This file may be overridden/superceded by mission-provided defintions
* either by overriding this header or by generating definitions from a command/data
* dictionary tool.
*/
#ifndef SAMPLE_APP_INTERFACE_CFG_H
#define SAMPLE_APP_INTERFACE_CFG_H

/**
* \brief Length of string buffer in the Display Value command
*
* The Display Value command offers an example of how to use command
* parameters of different types. This macro controls the length
* of the string parameter.
*/
#define SAMPLE_APP_STRING_VAL_LEN 10

#endif
2 changes: 1 addition & 1 deletion config/default_sample_app_internal_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/***********************************************************************/
#define SAMPLE_APP_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */

#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Table(s) */
#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Example Table(s) */

#define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1

Expand Down
2 changes: 1 addition & 1 deletion config/default_sample_app_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
#ifndef SAMPLE_APP_MISSION_CFG_H
#define SAMPLE_APP_MISSION_CFG_H

/* Placeholder - SAMPLE_APP currently has no mission-scope config options */
#include "sample_app_interface_cfg.h"

#endif
9 changes: 8 additions & 1 deletion config/default_sample_app_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@
#include "common_types.h"
#include "sample_app_fcncodes.h"

typedef struct SAMPLE_APP_DisplayParam_Payload
{
uint32 ValU32; /**< 32 bit unsigned integer value */
int16 ValI16; /**< 16 bit signed integer value */
char ValStr[SAMPLE_APP_STRING_VAL_LEN]; /**< An example string */
} SAMPLE_APP_DisplayParam_Payload_t;

/*************************************************************************/
/*
** Type definition (Sample App housekeeping)
*/

typedef struct
typedef struct SAMPLE_APP_HkTlm_Payload
{
uint8 CommandErrorCounter;
uint8 CommandCounter;
Expand Down
6 changes: 6 additions & 0 deletions config/default_sample_app_msgstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ typedef struct
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */
} SAMPLE_APP_ProcessCmd_t;

typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */
SAMPLE_APP_DisplayParam_Payload_t Payload;
} SAMPLE_APP_DisplayParamCmd_t;

/*************************************************************************/
/*
** Type definition (Sample App housekeeping)
Expand Down
2 changes: 1 addition & 1 deletion config/default_sample_app_tbldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ typedef struct
{
uint16 Int1;
uint16 Int2;
} SAMPLE_APP_Table_t;
} SAMPLE_APP_ExampleTable_t;

#endif
1 change: 1 addition & 0 deletions fsw/inc/sample_app_eventids.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
#define SAMPLE_APP_MID_ERR_EID 5
#define SAMPLE_APP_CMD_LEN_ERR_EID 6
#define SAMPLE_APP_PIPE_ERR_EID 7
#define SAMPLE_APP_VALUE_INF_EID 8

#endif /* SAMPLE_APP_EVENTS_H */
124 changes: 6 additions & 118 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
/*
** Include Files:
*/
#include <string.h>

#include "sample_app.h"
#include "sample_app_cmds.h"
#include "sample_app_utils.h"
#include "sample_app_eventids.h"
#include "sample_app_version.h"
#include "sample_app_dispatch.h"
#include "sample_app_tbl.h"
#include "sample_app_version.h"

/*
** global data
Expand Down Expand Up @@ -84,7 +83,7 @@ void SAMPLE_APP_Main(void)

if (status == CFE_SUCCESS)
{
SAMPLE_APP_ProcessCommandPacket(SBBufPtr);
SAMPLE_APP_TaskPipe(SBBufPtr);
}
else
{
Expand Down Expand Up @@ -178,13 +177,13 @@ int32 SAMPLE_APP_Init(void)
if (status == CFE_SUCCESS)
{
/*
** Register Table(s)
** Register Example Table(s)
*/
status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "SampleAppTable", sizeof(SAMPLE_APP_Table_t),
status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "ExampleTable", sizeof(SAMPLE_APP_ExampleTable_t),
CFE_TBL_OPT_DEFAULT, SAMPLE_APP_TblValidationFunc);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Error Registering Table, RC = 0x%08lX\n", (unsigned long)status);
CFE_ES_WriteToSysLog("Sample App: Error Registering Example Table, RC = 0x%08lX\n", (unsigned long)status);
}
else
{
Expand All @@ -197,114 +196,3 @@ int32 SAMPLE_APP_Init(void)

return status;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This routine will process any packet that is received on the Sample */
/* App command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId);

switch (CFE_SB_MsgIdToValue(MsgId))
{
case SAMPLE_APP_CMD_MID:
SAMPLE_APP_ProcessGroundCommand(SBBufPtr);
break;

case SAMPLE_APP_SEND_HK_MID:
SAMPLE_APP_ReportHousekeeping((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;

default:
CFE_EVS_SendEvent(SAMPLE_APP_MID_ERR_EID, CFE_EVS_EventType_ERROR,
"SAMPLE: invalid command packet,MID = 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MsgId));
break;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Process Ground Commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);

/*
** Process "known" Sample App ground commands
*/
switch (CommandCode)
{
case SAMPLE_APP_NOOP_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t)))
{
SAMPLE_APP_Noop((SAMPLE_APP_NoopCmd_t *)SBBufPtr);
}
break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t)))
{
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr);
}
break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t)))
{
SAMPLE_APP_Process((SAMPLE_APP_ProcessCmd_t *)SBBufPtr);
}
break;

/* default case already found during FC vs length test */
default:
CFE_EVS_SendEvent(SAMPLE_APP_CC_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid ground command code: CC = %d",
CommandCode);
break;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function is triggered in response to a task telemetry request */
/* from the housekeeping task. This function will gather the App's */
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg)
{
int i;

/*
** Get command execution counters...
*/
SAMPLE_APP_Data.HkTlm.Payload.CommandErrorCounter = SAMPLE_APP_Data.ErrCounter;
SAMPLE_APP_Data.HkTlm.Payload.CommandCounter = SAMPLE_APP_Data.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader));
CFE_SB_TransmitMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), true);

/*
** Manage any pending table loads, validations, etc.
*/
for (i = 0; i < SAMPLE_APP_NUMBER_OF_TABLES; i++)
{
CFE_TBL_Manage(SAMPLE_APP_Data.TblHandles[i]);
}

return CFE_SUCCESS;
}
3 changes: 0 additions & 3 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,5 @@ extern SAMPLE_APP_Data_t SAMPLE_APP_Data;
*/
void SAMPLE_APP_Main(void);
int32 SAMPLE_APP_Init(void);
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr);
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr);
int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg);

#endif /* SAMPLE_APP_H */
Loading