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 #30, Apply standard style #40

Merged
merged 2 commits into from
May 28, 2020
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
5 changes: 2 additions & 3 deletions fsw/mission_inc/sch_lab_perfids.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sch_lab_perfids.h
**
** Purpose:
** Purpose:
** Define SCH Lab Performance IDs
**
** Notes:
Expand All @@ -29,8 +29,7 @@
#ifndef _sch_lab_perfids_h_
#define _sch_lab_perfids_h_


#define SCH_MAIN_TASK_PERF_ID 36
#define SCH_MAIN_TASK_PERF_ID 36

#endif /* _sch_lab_perfids_h_ */

Expand Down
17 changes: 7 additions & 10 deletions fsw/platform_inc/sch_lab_sched_tab.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sch_lab_sched_tab.h
**
** Purpose:
** Purpose:
** This file contains the schedule tables for the SCH Lab app.
** It is intended to go in the platform include directory so the SCH_LAB
** app source code does not have to be modified.
Expand All @@ -29,8 +29,7 @@
**
*************************************************************************/


#include "cfe_sb_extern_typedefs.h" /* for CFE_SB_MsgId_t */
#include "cfe_sb_extern_typedefs.h" /* for CFE_SB_MsgId_t */
#include "cfe_msgids.h"

/*
Expand All @@ -52,22 +51,20 @@
/*
** Defines
*/
#define SCH_LAB_END_OF_TABLE 0
#define SCH_LAB_MAX_SCHEDULE_ENTRIES 32
#define SCH_TBL_DEFAULT_FILE "/cf/sch_lab_table.tbl"
#define SCH_LAB_END_OF_TABLE 0
#define SCH_LAB_MAX_SCHEDULE_ENTRIES 32
#define SCH_TBL_DEFAULT_FILE "/cf/sch_lab_table.tbl"

/*
** Typedefs
*/
typedef struct
{
CFE_SB_MsgId_t MessageID; /* Message ID for the table entry */
uint32 PacketRate; /* Rate: Send packet every N seconds */
CFE_SB_MsgId_t MessageID; /* Message ID for the table entry */
uint32 PacketRate; /* Rate: Send packet every N seconds */
} SCH_LAB_ScheduleTableEntry_t;


typedef struct
{
SCH_LAB_ScheduleTableEntry_t Config[SCH_LAB_MAX_SCHEDULE_ENTRIES];
} SCH_LAB_ScheduleTable_t;

142 changes: 63 additions & 79 deletions fsw/src/sch_lab_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
**
** File: sch_lab_app.c
**
** Purpose:
** Purpose:
** This file contains the source code for the SCH lab application
**
** Notes:
Expand Down Expand Up @@ -51,8 +51,8 @@
*/
typedef union
{
CFE_SB_Msg_t MsgHdr;
CFE_SB_CmdHdr_t CommandHeader;
CFE_SB_Msg_t MsgHdr;
CFE_SB_CmdHdr_t CommandHeader;
} SCH_LAB_MessageBuffer_t;

typedef struct
Expand All @@ -64,19 +64,18 @@ typedef struct

typedef struct
{
SCH_LAB_StateEntry_t State[SCH_LAB_MAX_SCHEDULE_ENTRIES];
CFE_TBL_Handle_t TblHandle;
SCH_LAB_StateEntry_t State[SCH_LAB_MAX_SCHEDULE_ENTRIES];
CFE_TBL_Handle_t TblHandle;

CFE_SB_Msg_t *CmdPipePktPtr;
CFE_SB_PipeId_t CmdPipe;
CFE_SB_Msg_t * CmdPipePktPtr;
CFE_SB_PipeId_t CmdPipe;

} SCH_LAB_GlobalData_t;

/*
** Global Variables
*/
SCH_LAB_GlobalData_t SCH_LAB_Global;

SCH_LAB_GlobalData_t SCH_LAB_Global;

/*
** Local Function Prototypes
Expand All @@ -88,47 +87,45 @@ int32 SCH_LAB_AppInit(void);
*/
void SCH_Lab_AppMain(void)
{
int i;
uint32 SCH_OneHzPktsRcvd = 0;
uint32 Status = CFE_SUCCESS;
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
int i;
uint32 SCH_OneHzPktsRcvd = 0;
uint32 Status = CFE_SUCCESS;
uint32 RunStatus = CFE_ES_RunStatus_APP_RUN;
SCH_LAB_StateEntry_t *LocalStateEntry;

CFE_ES_PerfLogEntry(SCH_MAIN_TASK_PERF_ID);

CFE_ES_RegisterApp();

Status = SCH_LAB_AppInit();
if ( Status != CFE_SUCCESS )
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Initializing RC = 0x%08lX\n",
(unsigned long)Status);
CFE_ES_WriteToSysLog("SCH_LAB: Error Initializing RC = 0x%08lX\n", (unsigned long)Status);
}

}

/* Loop Forever */
while (CFE_ES_RunLoop(&RunStatus) == true)
{
CFE_ES_PerfLogExit(SCH_MAIN_TASK_PERF_ID);

/* Pend on receipt of 1Hz packet */
Status = CFE_SB_RcvMsg(&SCH_LAB_Global.CmdPipePktPtr,SCH_LAB_Global.CmdPipe,CFE_SB_PEND_FOREVER);
Status = CFE_SB_RcvMsg(&SCH_LAB_Global.CmdPipePktPtr, SCH_LAB_Global.CmdPipe, CFE_SB_PEND_FOREVER);

CFE_ES_PerfLogEntry(SCH_MAIN_TASK_PERF_ID);

if(Status == CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
SCH_OneHzPktsRcvd++;
/*
** Process table every second, sending packets that are ready
** Process table every second, sending packets that are ready
*/
LocalStateEntry = SCH_LAB_Global.State;
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
{
if (LocalStateEntry->PacketRate != 0)
{
++LocalStateEntry->Counter;
if ( LocalStateEntry->Counter >= LocalStateEntry->PacketRate )
if (LocalStateEntry->Counter >= LocalStateEntry->PacketRate)
{
LocalStateEntry->Counter = 0;
CFE_SB_SendMsg(&LocalStateEntry->MsgBuf.MsgHdr);
Expand All @@ -138,84 +135,77 @@ void SCH_Lab_AppMain(void)
}
}

}/* end while */

CFE_ES_ExitApp( Status );

}/* end SCH_Lab_AppMain */
} /* end while */

CFE_ES_ExitApp(Status);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
} /* end SCH_Lab_AppMain */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* SCH_LAB_AppInit() -- initialization */
/* */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SCH_LAB_AppInit(void)
{
int i;
int32 Status;
SCH_LAB_ScheduleTable_t *ConfigTable;
{
int i;
int32 Status;
SCH_LAB_ScheduleTable_t * ConfigTable;
SCH_LAB_ScheduleTableEntry_t *ConfigEntry;
SCH_LAB_StateEntry_t *LocalStateEntry;
SCH_LAB_StateEntry_t * LocalStateEntry;

memset(&SCH_LAB_Global, 0, sizeof(SCH_LAB_Global));

/*
** Register tables with cFE and load default data
*/
Status = CFE_TBL_Register(&SCH_LAB_Global.TblHandle,
"SCH_LAB_SchTbl",
sizeof(SCH_LAB_ScheduleTable_t),
CFE_TBL_OPT_DEFAULT,
NULL);
Status = CFE_TBL_Register(&SCH_LAB_Global.TblHandle, "SCH_LAB_SchTbl", sizeof(SCH_LAB_ScheduleTable_t),
CFE_TBL_OPT_DEFAULT, NULL);

if ( Status != CFE_SUCCESS )
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Registering SCH_LAB_SchTbl, RC = 0x%08lX\n",
(unsigned long)Status);
CFE_ES_WriteToSysLog("SCH_LAB: Error Registering SCH_LAB_SchTbl, RC = 0x%08lX\n", (unsigned long)Status);

return ( Status );
return (Status);
}
else
{
/*
** Loading Table
*/
Status = CFE_TBL_Load(SCH_LAB_Global.TblHandle, CFE_TBL_SRC_FILE, SCH_TBL_DEFAULT_FILE);
if ( Status != CFE_SUCCESS )
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Loading Table SCH_LAB_SchTbl, RC = 0x%08lX\n",
(unsigned long)Status);
CFE_ES_WriteToSysLog("SCH_LAB: Error Loading Table SCH_LAB_SchTbl, RC = 0x%08lX\n", (unsigned long)Status);
CFE_TBL_ReleaseAddress(SCH_LAB_Global.TblHandle);

return ( Status );
return (Status);
}
}

/*
** Get Table Address
*/
*/
Status = CFE_TBL_GetAddress((void **)&ConfigTable, SCH_LAB_Global.TblHandle);
if ( Status != CFE_SUCCESS &&
Status != CFE_TBL_INFO_UPDATED )
if (Status != CFE_SUCCESS && Status != CFE_TBL_INFO_UPDATED)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Getting Table's Address SCH_LAB_SchTbl, RC = 0x%08lX\n",
(unsigned long)Status);
(unsigned long)Status);

return ( Status );
return (Status);
}

/*
** Initialize the command headers
*/
ConfigEntry = ConfigTable->Config;
ConfigEntry = ConfigTable->Config;
LocalStateEntry = SCH_LAB_Global.State;
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
for (i = 0; i < SCH_LAB_MAX_SCHEDULE_ENTRIES; i++)
{
if (ConfigEntry->PacketRate != 0)
{
CFE_SB_InitMsg(&LocalStateEntry->MsgBuf.MsgHdr,
ConfigEntry->MessageID,
sizeof(LocalStateEntry->MsgBuf), true);
CFE_SB_InitMsg(&LocalStateEntry->MsgBuf.MsgHdr, ConfigEntry->MessageID, sizeof(LocalStateEntry->MsgBuf),
true);
LocalStateEntry->PacketRate = ConfigEntry->PacketRate;
}
++ConfigEntry;
Expand All @@ -226,33 +216,27 @@ int32 SCH_LAB_AppInit(void)
** Release the table
*/
Status = CFE_TBL_ReleaseAddress(SCH_LAB_Global.TblHandle);
if ( Status != CFE_SUCCESS )
if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("SCH_LAB: Error Releasing Table SCH_LAB_SchTbl, RC = 0x%08lX\n",
(unsigned long)Status);

CFE_ES_WriteToSysLog("SCH_LAB: Error Releasing Table SCH_LAB_SchTbl, RC = 0x%08lX\n", (unsigned long)Status);
}

/* Create pipe and subscribe to the 1Hz pkt */
Status = CFE_SB_CreatePipe(&SCH_LAB_Global.CmdPipe,8,"SCH_LAB_CMD_PIPE");
if ( Status != CFE_SUCCESS )
Status = CFE_SB_CreatePipe(&SCH_LAB_Global.CmdPipe, 8, "SCH_LAB_CMD_PIPE");
if (Status != CFE_SUCCESS)
{
OS_printf("SCH Error creating pipe!\n");
OS_printf("SCH Error creating pipe!\n");
}
Status = CFE_SB_Subscribe(CFE_TIME_1HZ_CMD_MID,SCH_LAB_Global.CmdPipe);
if ( Status != CFE_SUCCESS )

Status = CFE_SB_Subscribe(CFE_TIME_1HZ_CMD_MID, SCH_LAB_Global.CmdPipe);
if (Status != CFE_SUCCESS)
{
OS_printf("SCH Error subscribing to 1hz!\n");
OS_printf("SCH Error subscribing to 1hz!\n");
}

OS_printf ("SCH Lab Initialized. Version %d.%d.%d.%d\n",
SCH_LAB_MAJOR_VERSION,
SCH_LAB_MINOR_VERSION,
SCH_LAB_REVISION,
SCH_LAB_MISSION_REV);

return( CFE_SUCCESS );
OS_printf("SCH Lab Initialized. Version %d.%d.%d.%d\n", SCH_LAB_MAJOR_VERSION, SCH_LAB_MINOR_VERSION,
SCH_LAB_REVISION, SCH_LAB_MISSION_REV);

}/*End of AppInit*/
return (CFE_SUCCESS);

} /*End of AppInit*/
34 changes: 15 additions & 19 deletions fsw/src/sch_lab_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,28 @@
**
*/

#include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */
#include "sch_lab_sched_tab.h"
#include "cfe_sb.h" /* Required to use the CFE_SB_MSGID_WRAP_VALUE macro */
#include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */
#include "sch_lab_sched_tab.h"
#include "cfe_sb.h" /* Required to use the CFE_SB_MSGID_WRAP_VALUE macro */

/*
** SCH Lab schedule table
** When populating this table:
** 1. Make sure the table is terminated by the SCH_LAB_END_OF_TABLE entry
** 2. You can have commented out entries, but a zero MID will terminate the table processing,
** 2. You can have commented out entries, but a zero MID will terminate the table processing,
** skipping the remaining entries.
** 3. If the table grows too big, increase SCH_LAB_MAX_SCHEDULE_ENTRIES
*/

SCH_LAB_ScheduleTable_t SCH_TBL_Structure =
{
.Config =
{
{ CFE_SB_MSGID_WRAP_VALUE(CFE_ES_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(CFE_SB_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(CI_LAB_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(TO_LAB_SEND_HK_MID), 4 },
{ CFE_SB_MSGID_WRAP_VALUE(SAMPLE_APP_SEND_HK_MID), 4 },
SCH_LAB_ScheduleTable_t SCH_TBL_Structure = {.Config = {
{CFE_SB_MSGID_WRAP_VALUE(CFE_ES_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(CFE_SB_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(CI_LAB_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(TO_LAB_SEND_HK_MID), 4},
{CFE_SB_MSGID_WRAP_VALUE(SAMPLE_APP_SEND_HK_MID), 4},
#if 0
{ SC_SEND_HK_MID, 4, 0 },
{ SC_1HZ_WAKEUP_MID, 1, 0 }, /* Example of a 1hz packet */
Expand All @@ -53,8 +50,7 @@ SCH_LAB_ScheduleTable_t SCH_TBL_Structure =
{ DS_SEND_HK_MID, 4, 0 },
{ LC_SEND_HK_MID, 4, 0 },
#endif
}
};
}};

/*
** The macro below identifies:
Expand All @@ -63,4 +59,4 @@ SCH_LAB_ScheduleTable_t SCH_TBL_Structure =
** 3) a brief description of the contents of the file image
** 4) the desired name of the table image binary file that is cFE compatible
*/
CFE_TBL_FILEDEF(SCH_TBL_Structure, SCH_LAB_APP.SCH_LAB_SchTbl, Schedule Lab MsgID Table, sch_lab_table.tbl )
CFE_TBL_FILEDEF(SCH_TBL_Structure, SCH_LAB_APP.SCH_LAB_SchTbl, Schedule Lab MsgID Table, sch_lab_table.tbl)
Loading