From 9974c15953fb64743de90eda9ced28e466c6a92a Mon Sep 17 00:00:00 2001 From: sdwoodbury Date: Thu, 6 May 2021 16:06:29 -0400 Subject: [PATCH 1/3] compile with latest cFS --- CMakeLists.txt | 5 ++- fsw/src/skeleton_app.c | 74 ++++++++++++++++++-------------------- fsw/src/skeleton_app.h | 24 ++++--------- fsw/src/skeleton_app_msg.h | 11 +++--- 4 files changed, 50 insertions(+), 64 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce30d65..1106177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,6 @@ 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) + diff --git a/fsw/src/skeleton_app.c b/fsw/src/skeleton_app.c index 85615c3..bda4f1a 100644 --- a/fsw/src/skeleton_app.c +++ b/fsw/src/skeleton_app.c @@ -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 @@ -69,14 +65,14 @@ void SKELETON_AppMain( void ) */ 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 { @@ -130,10 +126,9 @@ int32 SKELETON_AppInit( void ) /* ** Initialize housekeeping packet (clear user data area). */ - CFE_SB_InitMsg(&SKELETON_AppData.HkBuf.MsgHdr, + CFE_MSG_Init(&SKELETON_AppData.HkTlm.TlmHeader.Msg, SKELETON_APP_HK_TLM_MID, - sizeof(SKELETON_AppData.HkBuf), - true); + sizeof(SKELETON_AppData.HkTlm)); /* ** Create Software Bus message pipe. @@ -193,20 +188,20 @@ 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) { 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: @@ -226,11 +221,11 @@ 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 @@ -238,25 +233,25 @@ void SKELETON_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) 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; @@ -283,19 +278,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; @@ -363,27 +358,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; diff --git a/fsw/src/skeleton_app.h b/fsw/src/skeleton_app.h index 151d5e1..6f2140e 100644 --- a/fsw/src/skeleton_app.h +++ b/fsw/src/skeleton_app.h @@ -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 */ @@ -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 @@ -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; /****************************************************************************/ @@ -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 diff --git a/fsw/src/skeleton_app_msg.h b/fsw/src/skeleton_app_msg.h index 03f6bbd..6aac7ff 100644 --- a/fsw/src/skeleton_app_msg.h +++ b/fsw/src/skeleton_app_msg.h @@ -44,7 +44,7 @@ */ typedef struct { - uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE]; + CFE_MSG_CommandHeader_t CmdHeader; } SKELETON_NoArgsCmd_t; @@ -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 */ From f5fe74e372340fc4a6dba719456fe3322088ba21 Mon Sep 17 00:00:00 2001 From: Maxime Haselbauer Date: Sat, 4 Jun 2022 19:55:49 +0200 Subject: [PATCH 2/3] Adapt and to modern cfs and fix runtime issue --- fsw/src/skeleton_app.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/fsw/src/skeleton_app.c b/fsw/src/skeleton_app.c index bda4f1a..f06df4b 100644 --- a/fsw/src/skeleton_app.c +++ b/fsw/src/skeleton_app.c @@ -63,6 +63,7 @@ void SKELETON_AppMain( void ) /* ** SKELETON Runloop */ + while (CFE_ES_RunLoop(&SKELETON_AppData.RunStatus) == true) { status = CFE_SB_ReceiveBuffer(&SBBufPtr, @@ -110,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 @@ -127,7 +129,7 @@ int32 SKELETON_AppInit( void ) ** Initialize housekeeping packet (clear user data area). */ CFE_MSG_Init(&SKELETON_AppData.HkTlm.TlmHeader.Msg, - SKELETON_APP_HK_TLM_MID, + CFE_SB_ValueToMsgId(SKELETON_APP_HK_TLM_MID), sizeof(SKELETON_AppData.HkTlm)); /* @@ -146,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) { @@ -158,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 ) { @@ -194,7 +196,7 @@ void SKELETON_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr ) CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); - switch (MsgId) + switch (CFE_SB_MsgIdToValue(MsgId)) { case SKELETON_APP_CMD_MID: SKELETON_ProcessGroundCommand(SBBufPtr); @@ -208,7 +210,7 @@ void SKELETON_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr ) 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; } From 955d4ec37b6e5d40d94d1e81f9e61bf0569af11b Mon Sep 17 00:00:00 2001 From: Maxime Haselbauer Date: Sat, 4 Jun 2022 22:32:16 +0200 Subject: [PATCH 3/3] Refactor the CMakeLists.txt --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1106177..24e477d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,9 @@ cmake_minimum_required(VERSION 2.6.4) project(CFE_SKELETON_APP C) -include_directories(fsw/mission_inc) -include_directories(fsw/platform_inc) - # Create the app module add_cfe_app(skeleton_app fsw/src/skeleton_app.c) +target_include_directories(skeleton_app PUBLIC + $ + $ )