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

Fixing direct import of skeleton_app into latest cfs #6

Open
wants to merge 2 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
6 changes: 3 additions & 3 deletions fsw/platform_inc/skeleton_app_msgids.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
#ifndef _skeleton_app_msgids_h_
#define _skeleton_app_msgids_h_

#define SKELETON_APP_CMD_MID 0x1882
#define SKELETON_APP_SEND_HK_MID 0x1883
#define SKELETON_APP_HK_TLM_MID 0x0883
#define SKELETON_APP_CMD_MID 0x1872
#define SKELETON_APP_SEND_HK_MID 0x1873
#define SKELETON_APP_HK_TLM_MID 0x0873

#endif /* _skeleton_app_msgids_h_ */

Expand Down
75 changes: 36 additions & 39 deletions fsw/src/skeleton_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ void SKELETON_AppMain( void )
{
int32 status;

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

/*
** Perform application specific initialization
** If the Initialization fails, set the RunStatus to
Expand All @@ -69,14 +64,12 @@ void SKELETON_AppMain( void )
*/
while (CFE_ES_RunLoop(&SKELETON_AppData.RunStatus) == true)
{
status = CFE_SB_RcvMsg(&SKELETON_AppData.MsgPtr,
SKELETON_AppData.CommandPipe,
CFE_SB_PEND_FOREVER);

/* Pend on receipt of command packet */
status = CFE_SB_ReceiveBuffer(&SKELETON_AppData.SBBufPtr, SKELETON_AppData.CommandPipe, CFE_SB_PEND_FOREVER);

if (status == CFE_SUCCESS)
{
SKELETON_ProcessCommandPacket(SKELETON_AppData.MsgPtr);
SKELETON_ProcessCommandPacket(SKELETON_AppData.SBBufPtr);
}
else
{
Expand Down Expand Up @@ -115,7 +108,8 @@ int32 SKELETON_AppInit( void )
*/
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 +124,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.HkBuf.TlmHeader.Msg,
SKELETON_APP_HK_TLM_MID,
sizeof(SKELETON_AppData.HkBuf));

/*
** Create Software Bus message pipe.
Expand Down Expand Up @@ -193,27 +186,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;

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:
CFE_EVS_SendEvent(SKELETON_INVALID_MSGID_ERR_EID,
CFE_EVS_EventType_ERROR,
"SKELETON: invalid command packet,MID = 0x%x",
MsgId);
"SKELETON: invalid command packet,MID = 0x%x",
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
break;
}

Expand All @@ -226,37 +219,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;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to check the return value == CFE_SUCCESS


/*
** 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 +276,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.HkBuf.Payload.CommandErrorCounter = SKELETON_AppData.ErrCounter;
SKELETON_AppData.HkBuf.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.HkBuf.TlmHeader.Msg);
CFE_SB_TransmitMsg(&SKELETON_AppData.HkBuf.TlmHeader.Msg, true);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above, should check return code (I realize the old code did not check return codes on these either :D )


return CFE_SUCCESS;

Expand Down Expand Up @@ -363,19 +356,23 @@ 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, CFE_MSG_Size_t ExpectedLength )
{
bool result = true;
CFE_MSG_Size_t ActualLength;

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment, check return value in case the message is mangled


/*
** Verify the command packet length.
*/
if (ExpectedLength != ActualLength)
{
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(Msg);
uint16 CommandCode = CFE_SB_GetCmdCode(Msg);
CFE_SB_MsgId_t MessageID;
CFE_MSG_FcnCode_t CommandCode;

CFE_MSG_GetMsgId(MsgPtr, &MessageID);
CFE_MSG_GetFcnCode(MsgPtr, &CommandCode);

CFE_EVS_SendEvent(SKELETON_LEN_ERR_EID,
CFE_EVS_EventType_ERROR,
Expand Down
25 changes: 8 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 HkBuf;

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

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

Expand All @@ -101,13 +92,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, CFE_MSG_Size_t ExpectedLength);

#endif /* _skeleton_app_h_ */
6 changes: 3 additions & 3 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; /**< \brief Command header */

} SKELETON_NoArgsCmd_t;

Expand Down Expand Up @@ -73,10 +73,10 @@ typedef struct

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

} OS_PACK SKELETON_HkTlm_t;
} SKELETON_HkTlm_t;

#endif /* _skeleton_app_msg_h_ */

Expand Down