Skip to content

Commit

Permalink
Added cmds and utils files and moved functions from app.c to them.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejtimmon committed Apr 14, 2020
1 parent b956292 commit ab2acdc
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 199 deletions.
197 changes: 6 additions & 191 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include "sample_app_version.h"
#include "sample_app.h"
#include "sample_table.h"
#include "sample_app_cmds.h"
#include "sample_app_utils.h"

/* The sample_lib module provides the SAMPLE_Function() prototype */
#include <string.h>
Expand Down Expand Up @@ -277,7 +279,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
default:
CFE_EVS_SendEvent(SAMPLE_INVALID_MSGID_ERR_EID,
CFE_EVS_EventType_ERROR,
"SAMPLE: invalid command packet,MID = 0x%x",
"SAMPLE: invalid command packet,MID = 0x%x",
MsgId);
break;
}
Expand All @@ -303,27 +305,15 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
switch (CommandCode)
{
case SAMPLE_APP_NOOP_CC:
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
{
SAMPLE_Noop((SAMPLE_Noop_t *)Msg);
}

SAMPLE_Noop((SAMPLE_Noop_t *)Msg);
break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t)))
{
SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg);
}

SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg);
break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t)))
{
SAMPLE_Process((SAMPLE_Process_t *)Msg);
}

SAMPLE_Process((SAMPLE_Process_t *)Msg);
break;

/* default case already found during FC vs length test */
Expand Down Expand Up @@ -376,179 +366,4 @@ int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )

} /* End of SAMPLE_ReportHousekeeping() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE_Noop -- SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_Noop( const SAMPLE_Noop_t *Msg )
{

SAMPLE_AppData.CmdCounter++;

CFE_EVS_SendEvent(SAMPLE_COMMANDNOP_INF_EID,
CFE_EVS_EventType_INFORMATION,
"SAMPLE: NOOP command Version %d.%d.%d.%d",
SAMPLE_APP_MAJOR_VERSION,
SAMPLE_APP_MINOR_VERSION,
SAMPLE_APP_REVISION,
SAMPLE_APP_MISSION_REV);

return CFE_SUCCESS;

} /* End of SAMPLE_Noop */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: SAMPLE_ResetCounters */
/* */
/* Purpose: */
/* This function resets all the global counter variables that are */
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg )
{

SAMPLE_AppData.CmdCounter = 0;
SAMPLE_AppData.ErrCounter = 0;

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

return CFE_SUCCESS;

} /* End of SAMPLE_ResetCounters() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: SAMPLE_Process */
/* */
/* Purpose: */
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_Process( const SAMPLE_Process_t *Msg )
{
int32 status;
SAMPLE_Table_t *TblPtr;
const char *TableName = "SAMPLE_APP.SampleTable";

/* Sample Use of Table */

status = CFE_TBL_GetAddress((void *)&TblPtr,
SAMPLE_AppData.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_GetCrc(TableName);

status = CFE_TBL_ReleaseAddress(SAMPLE_AppData.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_LIB */
SAMPLE_Function();

return CFE_SUCCESS;

} /* End of SAMPLE_ProcessCC */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE_VerifyCmdLength() -- Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength )
{
bool result = true;

uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg);

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

CFE_EVS_SendEvent(SAMPLE_LEN_ERR_EID,
CFE_EVS_EventType_ERROR,
"Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d",
MessageID,
CommandCode,
ActualLength,
ExpectedLength);

result = false;

SAMPLE_AppData.ErrCounter++;
}

return( result );

} /* End of SAMPLE_VerifyCmdLength() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* SAMPLE_TblValidationFunc -- Verify contents of First Table */
/* buffer contents */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_TblValidationFunc( void *TblData )
{
int32 ReturnCode = CFE_SUCCESS;
SAMPLE_Table_t *TblDataPtr = (SAMPLE_Table_t *)TblData;

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

return ReturnCode;

} /* End of Sample_TblValidationFunc*/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* SAMPLE_GetCrc -- Output CRC */
/* */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_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);
}

return;

} /* End of SAMPLE_GetCrc */
8 changes: 0 additions & 8 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,5 @@ int32 SAMPLE_AppInit(void);
void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg);
void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg);
int32 SAMPLE_ReportHousekeeping(const CCSDS_CommandPacket_t *Msg);
int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg);
int32 SAMPLE_Process(const SAMPLE_Process_t *Msg);
int32 SAMPLE_Noop(const SAMPLE_Noop_t *Msg);
void SAMPLE_GetCrc(const char *TableName);

int32 SAMPLE_TblValidationFunc(void *TblData);

bool SAMPLE_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength);

#endif /* _sample_app_h_ */
148 changes: 148 additions & 0 deletions fsw/src/sample_app_cmds.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*******************************************************************************
**
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 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
**
** 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_cmds.c
**
** Purpose:
** This file contains the source code for the Sample App command handling
** functions.
**
*******************************************************************************/

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

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


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE_Noop -- SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_Noop( const SAMPLE_Noop_t *Msg )
{

if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
{
SAMPLE_AppData.CmdCounter++;

CFE_EVS_SendEvent(SAMPLE_COMMANDNOP_INF_EID,
CFE_EVS_EventType_INFORMATION,
"SAMPLE: NOOP command Version %d.%d.%d.%d",
SAMPLE_APP_MAJOR_VERSION,
SAMPLE_APP_MINOR_VERSION,
SAMPLE_APP_REVISION,
SAMPLE_APP_MISSION_REV);
}

return CFE_SUCCESS;

} /* End of SAMPLE_Noop */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: SAMPLE_ResetCounters */
/* */
/* Purpose: */
/* This function resets all the global counter variables that are */
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg )
{

if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
{
SAMPLE_AppData.CmdCounter = 0;
SAMPLE_AppData.ErrCounter = 0;

CFE_EVS_SendEvent(SAMPLE_COMMANDRST_INF_EID,
CFE_EVS_EventType_INFORMATION,
"SAMPLE: RESET command");
}

return CFE_SUCCESS;

} /* End of SAMPLE_ResetCounters() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: SAMPLE_Process */
/* */
/* Purpose: */
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_Process( const SAMPLE_Process_t *Msg )
{
int32 status;
SAMPLE_Table_t *TblPtr;
const char *TableName = "SAMPLE_APP.SampleTable";


if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
{
/* Sample Use of Table */

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

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

SAMPLE_AppData.ErrCounter++;
return;
}

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

SAMPLE_GetCrc(TableName);

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

SAMPLE_AppData.ErrCounter++;
return;
}

/* Invoke a function provided by SAMPLE_LIB */
SAMPLE_Function();

SAMPLE_AppData.CmdCounter++;
}

} /* End of SAMPLE_ProcessCC */


Loading

0 comments on commit ab2acdc

Please sign in to comment.