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

Modern cmake for skeleton app #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 2.6.4)
project(CFE_SKELETON_APP C)

include_directories(fsw/mission_inc)
include_directories(fsw/platform_inc)

aux_source_directory(fsw/src APP_SRC_FILES)

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

target_include_directories(skeleton_app PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/fsw/platform_inc>
$<INSTALL_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/fsw/platform_inc> )
90 changes: 44 additions & 46 deletions fsw/src/skeleton_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ SKELETON_AppData_t SKELETON_AppData;
void SKELETON_AppMain( void )
{
int32 status;

/*
** Register the app with Executive services
*/
CFE_ES_RegisterApp();
CFE_SB_Buffer_t *SBBufPtr;

/*
** Perform application specific initialization
Expand All @@ -67,16 +63,17 @@ void SKELETON_AppMain( void )
/*
** SKELETON Runloop
*/

while (CFE_ES_RunLoop(&SKELETON_AppData.RunStatus) == true)
{
status = CFE_SB_RcvMsg(&SKELETON_AppData.MsgPtr,
status = CFE_SB_ReceiveBuffer(&SBBufPtr,
SKELETON_AppData.CommandPipe,
CFE_SB_PEND_FOREVER);


if (status == CFE_SUCCESS)
{
SKELETON_ProcessCommandPacket(SKELETON_AppData.MsgPtr);
SKELETON_ProcessCommandPacket(SBBufPtr);
}
else
{
Expand Down Expand Up @@ -114,8 +111,9 @@ int32 SKELETON_AppInit( void )
** Initialize app configuration data
*/
SKELETON_AppData.PipeDepth = SKELETON_PIPE_DEPTH;

strcpy(SKELETON_AppData.PipeName, "SKELETON_CMD_PIPE");

strncpy(SKELETON_AppData.PipeName, "SKELETON_CMD_PIPE", sizeof(SKELETON_AppData.PipeName));
SKELETON_AppData.PipeName[sizeof(SKELETON_AppData.PipeName) - 1] = 0;

/*
** Register the events
Expand All @@ -130,10 +128,9 @@ int32 SKELETON_AppInit( void )
/*
** Initialize housekeeping packet (clear user data area).
*/
CFE_SB_InitMsg(&SKELETON_AppData.HkBuf.MsgHdr,
SKELETON_APP_HK_TLM_MID,
sizeof(SKELETON_AppData.HkBuf),
true);
CFE_MSG_Init(&SKELETON_AppData.HkTlm.TlmHeader.Msg,
CFE_SB_ValueToMsgId(SKELETON_APP_HK_TLM_MID),
sizeof(SKELETON_AppData.HkTlm));

/*
** Create Software Bus message pipe.
Expand All @@ -151,7 +148,7 @@ int32 SKELETON_AppInit( void )
/*
** Subscribe to Housekeeping request commands
*/
status = CFE_SB_Subscribe(SKELETON_APP_SEND_HK_MID,
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SKELETON_APP_SEND_HK_MID),
SKELETON_AppData.CommandPipe);
if (status != CFE_SUCCESS)
{
Expand All @@ -163,7 +160,7 @@ int32 SKELETON_AppInit( void )
/*
** Subscribe to ground command packets
*/
status = CFE_SB_Subscribe(SKELETON_APP_CMD_MID,
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SKELETON_APP_CMD_MID),
SKELETON_AppData.CommandPipe);
if (status != CFE_SUCCESS )
{
Expand Down Expand Up @@ -193,27 +190,27 @@ int32 SKELETON_AppInit( void )
/* command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SKELETON_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
void SKELETON_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr )
{
CFE_SB_MsgId_t MsgId;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

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

switch (MsgId)
switch (CFE_SB_MsgIdToValue(MsgId))
{
case SKELETON_APP_CMD_MID:
SKELETON_ProcessGroundCommand(Msg);
SKELETON_ProcessGroundCommand(SBBufPtr);
break;

case SKELETON_APP_SEND_HK_MID:
SKELETON_ReportHousekeeping((CCSDS_CommandPacket_t *)Msg);
SKELETON_ReportHousekeeping((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;

default:
CFE_EVS_SendEvent(SKELETON_INVALID_MSGID_ERR_EID,
CFE_EVS_EventType_ERROR,
"SKELETON: invalid command packet,MID = 0x%x",
MsgId);
CFE_SB_MsgIdToValue(MsgId));
break;
}

Expand All @@ -226,37 +223,37 @@ void SKELETON_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
/* SKELETON_ProcessGroundCommand() -- SKELETON ground commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SKELETON_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
void SKELETON_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr )
{
uint16 CommandCode;
CFE_MSG_FcnCode_t CommandCode = 0;

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

/*
** Process "known" SKELETON app ground commands
*/
switch (CommandCode)
{
case SKELETON_APP_NOOP_CC:
if (SKELETON_VerifyCmdLength(Msg, sizeof(SKELETON_Noop_t)))
if (SKELETON_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SKELETON_Noop_t)))
{
SKELETON_Noop((SKELETON_Noop_t *)Msg);
SKELETON_Noop((SKELETON_Noop_t *)SBBufPtr);
}

break;

case SKELETON_APP_RESET_COUNTERS_CC:
if (SKELETON_VerifyCmdLength(Msg, sizeof(SKELETON_ResetCounters_t)))
if (SKELETON_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SKELETON_ResetCounters_t)))
{
SKELETON_ResetCounters((SKELETON_ResetCounters_t *)Msg);
SKELETON_ResetCounters((SKELETON_ResetCounters_t *)SBBufPtr);
}

break;

case SKELETON_APP_PROCESS_CC:
if (SKELETON_VerifyCmdLength(Msg, sizeof(SKELETON_Process_t)))
if (SKELETON_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SKELETON_Process_t)))
{
SKELETON_Process((SKELETON_Process_t *)Msg);
SKELETON_Process((SKELETON_Process_t *)SBBufPtr);
}

break;
Expand All @@ -283,19 +280,19 @@ void SKELETON_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SKELETON_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )
int32 SKELETON_ReportHousekeeping( const CFE_MSG_CommandHeader_t *Msg )
{
/*
** Get command execution counters...
*/
SKELETON_AppData.HkBuf.HkTlm.Payload.CommandErrorCounter = SKELETON_AppData.ErrCounter;
SKELETON_AppData.HkBuf.HkTlm.Payload.CommandCounter = SKELETON_AppData.CmdCounter;
SKELETON_AppData.HkTlm.Payload.CommandErrorCounter = SKELETON_AppData.ErrCounter;
SKELETON_AppData.HkTlm.Payload.CommandCounter = SKELETON_AppData.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(&SKELETON_AppData.HkBuf.MsgHdr);
CFE_SB_SendMsg(&SKELETON_AppData.HkBuf.MsgHdr);
CFE_SB_TimeStampMsg(&SKELETON_AppData.HkTlm.TlmHeader.Msg);
CFE_SB_TransmitMsg(&SKELETON_AppData.HkTlm.TlmHeader.Msg, true);

return CFE_SUCCESS;

Expand Down Expand Up @@ -363,27 +360,28 @@ int32 SKELETON_Process( const SKELETON_Process_t *Msg )
/* SKELETON_VerifyCmdLength() -- Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool SKELETON_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength )
bool SKELETON_VerifyCmdLength( CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength )
{
bool result = true;
bool result = true;
size_t ActualLength = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t FcnCode = 0;

uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg);
CFE_MSG_GetSize(MsgPtr, &ActualLength);

/*
** Verify the command packet length.
*/
if (ExpectedLength != ActualLength)
{
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(Msg);
uint16 CommandCode = CFE_SB_GetCmdCode(Msg);
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);

CFE_EVS_SendEvent(SKELETON_LEN_ERR_EID,
CFE_EVS_EventType_ERROR,
"Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d",
MessageID,
CommandCode,
ActualLength,
ExpectedLength);
"Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength,
(unsigned int)ExpectedLength);

result = false;

Expand Down
24 changes: 7 additions & 17 deletions fsw/src/skeleton_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,6 @@
** Type Definitions
*************************************************************************/

/*
* Buffer to hold telemetry data prior to sending
* Defined as a union to ensure proper alignment for a CFE_SB_Msg_t type
*/
typedef union
{
CFE_SB_Msg_t MsgHdr;
SKELETON_HkTlm_t HkTlm;
} SKELETON_HkBuffer_t;

/*
** Global Data
*/
Expand All @@ -72,7 +62,7 @@ typedef struct
/*
** Housekeeping telemetry packet...
*/
SKELETON_HkBuffer_t HkBuf;
SKELETON_HkTlm_t HkTlm;

/*
** Run Status variable used in the main processing loop
Expand All @@ -83,13 +73,13 @@ typedef struct
** Operational data (not reported in housekeeping)...
*/
CFE_SB_PipeId_t CommandPipe;
CFE_SB_MsgPtr_t MsgPtr;

/*
** Initialization data (not reported in housekeeping)...
*/
char PipeName[16];
uint16 PipeDepth;

} SKELETON_AppData_t;

/****************************************************************************/
Expand All @@ -101,13 +91,13 @@ typedef struct
*/
void SKELETON_AppMain(void);
int32 SKELETON_AppInit(void);
void SKELETON_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg);
void SKELETON_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg);
int32 SKELETON_ReportHousekeeping(const CCSDS_CommandPacket_t *Msg);
void SKELETON_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr);
void SKELETON_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr);
int32 SKELETON_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg);
int32 SKELETON_ResetCounters(const SKELETON_ResetCounters_t *Msg);
int32 SKELETON_Process(const SKELETON_Process_t *Msg);
int32 SKELETON_Noop(const SKELETON_Noop_t *Msg);
void SKELETON_GetCrc(const char *TableName);
bool SKELETON_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength);
bool SKELETON_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength);

#endif /* _skeleton_app_h_ */
#endif
11 changes: 6 additions & 5 deletions fsw/src/skeleton_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
typedef struct
{
uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE];
CFE_MSG_CommandHeader_t CmdHeader;

} SKELETON_NoArgsCmd_t;

Expand All @@ -69,16 +69,17 @@ typedef struct
uint8 CommandErrorCounter;
uint8 CommandCounter;
uint8 spare[2];

} SKELETON_HkTlm_Payload_t;

typedef struct
{
uint8 TlmHeader[CFE_SB_TLM_HDR_SIZE];
SKELETON_HkTlm_Payload_t Payload;
CFE_MSG_TelemetryHeader_t TlmHeader; /**< \brief Telemetry header */
SKELETON_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */

} OS_PACK SKELETON_HkTlm_t;
} SKELETON_HkTlm_t;

#endif /* _skeleton_app_msg_h_ */
#endif

/************************/
/* End of File Comment */
Expand Down