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 #45, Move cmds and utils into separate files #205

Merged
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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
project(CFE_SAMPLE_APP C)

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

# Include the public API from sample_lib to demonstrate how
# to call library-provided functions
Expand Down
161 changes: 5 additions & 156 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
/*
** Include Files:
*/
#include <string.h>

#include "sample_app.h"
#include "sample_app_cmds.h"
#include "sample_app_utils.h"
#include "sample_app_events.h"
#include "sample_app_version.h"
#include "sample_app.h"
#include "sample_app_table.h"

/* The sample_lib module provides the SAMPLE_LIB_Function() prototype */
#include <string.h>
#include "sample_lib.h"

/*
** global data
*/
Expand Down Expand Up @@ -309,154 +309,3 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg)

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg)
{
SAMPLE_APP_Data.CmdCounter++;

CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s",
SAMPLE_APP_VERSION);

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function resets all the global counter variables that are */
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg)
{
SAMPLE_APP_Data.CmdCounter = 0;
SAMPLE_APP_Data.ErrCounter = 0;

CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command");

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg)
{
int32 status;
SAMPLE_APP_Table_t *TblPtr;
const char * TableName = "SAMPLE_APP.SampleAppTable";

/* Sample Use of Table */

status = CFE_TBL_GetAddress((void *)&TblPtr, SAMPLE_APP_Data.TblHandles[0]);

if (status < CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)status);
return status;
}

CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2);

SAMPLE_APP_GetCrc(TableName);

status = CFE_TBL_ReleaseAddress(SAMPLE_APP_Data.TblHandles[0]);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", (unsigned long)status);
return status;
}

/* Invoke a function provided by SAMPLE_APP_LIB */
SAMPLE_LIB_Function();

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
bool result = true;
size_t ActualLength = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t FcnCode = 0;

CFE_MSG_GetSize(MsgPtr, &ActualLength);

/*
** Verify the command packet length.
*/
if (ExpectedLength != ActualLength)
{
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);

CFE_EVS_SendEvent(SAMPLE_APP_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
"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;

SAMPLE_APP_Data.ErrCounter++;
}

return result;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Verify contents of First Table buffer contents */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_TblValidationFunc(void *TblData)
{
int32 ReturnCode = CFE_SUCCESS;
SAMPLE_APP_Table_t *TblDataPtr = (SAMPLE_APP_Table_t *)TblData;

/*
** Sample Table Validation
*/
if (TblDataPtr->Int1 > SAMPLE_APP_TBL_ELEMENT_1_MAX)
{
/* First element is out of range, return an appropriate error code */
ReturnCode = SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE;
}

return ReturnCode;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Output CRC */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_APP_GetCrc(const char *TableName)
{
int32 status;
uint32 Crc;
CFE_TBL_Info_t TblInfoPtr;

status = CFE_TBL_GetInfo(&TblInfoPtr, TableName);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info");
}
else
{
Crc = TblInfoPtr.Crc;
CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)Crc);
}
}
13 changes: 5 additions & 8 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ typedef struct
CFE_TBL_Handle_t TblHandles[SAMPLE_APP_NUMBER_OF_TABLES];
} SAMPLE_APP_Data_t;

/*
** Global data structure
*/
extern SAMPLE_APP_Data_t SAMPLE_APP_Data;

/****************************************************************************/
/*
** Local function prototypes.
Expand All @@ -100,13 +105,5 @@ 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);
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg);
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg);
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg);
void SAMPLE_APP_GetCrc(const char *TableName);

int32 SAMPLE_APP_TblValidationFunc(void *TblData);

bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength);

#endif /* SAMPLE_APP_H */
107 changes: 107 additions & 0 deletions fsw/src/sample_app_cmds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/************************************************************************
* 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://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
* This file contains the source code for the Sample App Ground Command-handling functions
*/

/*
** Include Files:
*/
#include "sample_app.h"
#include "sample_app_cmds.h"
#include "sample_app_events.h"
#include "sample_app_version.h"
#include "sample_app_table.h"
#include "sample_app_utils.h"
#include "sample_app_msg.h"

/* The sample_lib module provides the SAMPLE_Function() prototype */
#include "sample_lib.h"

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg)
{
SAMPLE_APP_Data.CmdCounter++;

CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s",
SAMPLE_APP_VERSION);

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function resets all the global counter variables that are */
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg)
{
SAMPLE_APP_Data.CmdCounter = 0;
SAMPLE_APP_Data.ErrCounter = 0;

CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command");

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg)

Check notice

Code scanning / CodeQL

Long function without assertion

All functions of more than 10 lines should have at least one assertion.
{
int32 status;
SAMPLE_APP_Table_t *TblPtr;
const char * TableName = "SAMPLE_APP.SampleAppTable";

/* Sample Use of Table */

status = CFE_TBL_GetAddress((void *)&TblPtr, SAMPLE_APP_Data.TblHandles[0]);

if (status < CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)status);
return status;
}

CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2);

SAMPLE_APP_GetCrc(TableName);

status = CFE_TBL_ReleaseAddress(SAMPLE_APP_Data.TblHandles[0]);
if (status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", (unsigned long)status);
return status;
}

/* Invoke a function provided by SAMPLE_APP_LIB */
SAMPLE_LIB_Function();

return CFE_SUCCESS;
}
36 changes: 36 additions & 0 deletions fsw/src/sample_app_cmds.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/************************************************************************
* 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://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
* This file contains the prototypes for the Sample App Ground Command-handling functions
*/

#ifndef SAMPLE_APP_CMDS_H
#define SAMPLE_APP_CMDS_H

/*
** Required header files.
*/
#include "sample_app.h"

int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg);
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg);
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg);

#endif /* SAMPLE_APP_CMDS_H */
Loading