Skip to content

Commit

Permalink
Add blink command
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffstjean committed Mar 25, 2021
1 parent fe7510a commit b737f52
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 30 deletions.
71 changes: 44 additions & 27 deletions apps/sample_app/fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ void SAMPLE_APP_Main(void) {
int32 status; // return status of function calls
CFE_SB_Buffer_t *SBBufPtr; // pointer to software bus

bool led_status = true;

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

Expand Down Expand Up @@ -47,26 +45,12 @@ void SAMPLE_APP_Main(void) {
*/
status = CFE_SB_ReceiveBuffer(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, 1000);
if(status == CFE_SUCCESS) {
CFE_EVS_SendEvent(SAMPLE_APP_FILE_ERR_EID, CFE_EVS_EventType_CRITICAL, "SAMPLE: Recvd msg");
SAMPLE_APP_ProcessCommandPacket(SBBufPtr);
}

// Performance Log Exit Stamp
CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID);

// update led status
led_status = !led_status;

// Use RPI library to access hardware
status = RPI_Set_LED(led_status);
if(status == CFE_SUCCESS) {
CFE_EVS_SendEvent(SAMPLE_APP_FILE_ERR_EID, CFE_EVS_EventType_DEBUG, "SAMPLE: Toggled LED");
}
else {
// Error writing to RPI files
CFE_EVS_SendEvent(SAMPLE_APP_FILE_ERR_EID, CFE_EVS_EventType_ERROR, "SAMPLE: Unable to write to file");
}


// Performance Log Entry Stamp
CFE_ES_PerfLogEntry(SAMPLE_APP_PERF_ID);

Expand Down Expand Up @@ -116,6 +100,8 @@ int32 SAMPLE_APP_Init(void) {
SAMPLE_APP_Data.EventFilters[6].EventID = SAMPLE_APP_PIPE_ERR_EID;
SAMPLE_APP_Data.EventFilters[6].Mask = 0x0000;

SAMPLE_APP_Data.led_status = 0;

// Register the events
status = CFE_EVS_Register(SAMPLE_APP_Data.EventFilters, SAMPLE_APP_EVENT_COUNTS, CFE_EVS_EventFilter_BINARY);
if (status != CFE_SUCCESS) {
Expand Down Expand Up @@ -213,41 +199,43 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
/* SAMPLE_APP_ProcessGroundCommand() -- SAMPLE ground commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr)
{
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) {
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);

/*
** Process "known" SAMPLE app ground commands
*/
switch (CommandCode)
{
switch (CommandCode) {
case SAMPLE_APP_NOOP_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t)))
{
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t))) {
SAMPLE_APP_Noop((SAMPLE_APP_NoopCmd_t *)SBBufPtr);
}

break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t)))
{
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t))) {
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr);
}

break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t)))
{
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t))) {
SAMPLE_APP_Process((SAMPLE_APP_ProcessCmd_t *)SBBufPtr);
}

break;

case SAMPLE_APP_BLINK_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_BlinkCmd_t))) {
SAMPLE_APP_Blink((SAMPLE_APP_BlinkCmd_t *)SBBufPtr);
}

break;

/* default case already found during FC vs length test */
default:
CFE_EVS_SendEvent(SAMPLE_APP_COMMAND_ERR_EID, CFE_EVS_EventType_ERROR,
Expand Down Expand Up @@ -372,6 +360,35 @@ int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg)

} /* End of SAMPLE_APP_ProcessCC */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: SAMPLE_APP_Blink */
/* */
/* Purpose: */
/* This function Process Blink Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_Blink(const SAMPLE_APP_BlinkCmd_t *Msg) {
int32 status;

// update led status
SAMPLE_APP_Data.led_status = !SAMPLE_APP_Data.led_status;

// Use RPI library to access hardware
status = RPI_Set_LED(SAMPLE_APP_Data.led_status);
if(status == CFE_SUCCESS) {
CFE_EVS_SendEvent(SAMPLE_APP_BLINK_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: Blink command (%d) %s",
SAMPLE_APP_Data.led_status, SAMPLE_APP_VERSION);
}
else {
// Error writing to RPI files
CFE_EVS_SendEvent(SAMPLE_APP_FILE_ERR_EID, CFE_EVS_EventType_ERROR, "SAMPLE: Unable to write to file");
}


return status;

} /* End of SAMPLE_APP_BlinkCC */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE_APP_VerifyCmdLength() -- Verify command packet length */
Expand Down
3 changes: 3 additions & 0 deletions apps/sample_app/fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ typedef struct
CFE_EVS_BinFilter_t EventFilters[SAMPLE_APP_EVENT_COUNTS];
CFE_TBL_Handle_t TblHandles[SAMPLE_APP_NUMBER_OF_TABLES];

bool led_status;

} SAMPLE_APP_Data_t;

/****************************************************************************/
Expand All @@ -108,6 +110,7 @@ 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_Blink(const SAMPLE_APP_BlinkCmd_t *Msg);
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg);
void SAMPLE_APP_GetCrc(const char *TableName);

Expand Down
3 changes: 2 additions & 1 deletion apps/sample_app/fsw/src/sample_app_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#define SAMPLE_APP_LEN_ERR_EID 6 // Invalid Length
#define SAMPLE_APP_PIPE_ERR_EID 7 // Pipe Error (Software Bus)
#define SAMPLE_APP_FILE_ERR_EID 8 // File Write Error
#define SAMPLE_APP_BLINK_INF_EID 9 // Command Blink

#define SAMPLE_APP_EVENT_COUNTS 8
#define SAMPLE_APP_EVENT_COUNTS 9

#endif
2 changes: 2 additions & 0 deletions apps/sample_app/fsw/src/sample_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#define SAMPLE_APP_NOOP_CC 0
#define SAMPLE_APP_RESET_COUNTERS_CC 1
#define SAMPLE_APP_PROCESS_CC 2
#define SAMPLE_APP_BLINK_CC 3

/*************************************************************************/

Expand All @@ -35,6 +36,7 @@ typedef struct {
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_NoopCmd_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ResetCountersCmd_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ProcessCmd_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_BlinkCmd_t;

/*************************************************************************/
/*
Expand Down
2 changes: 2 additions & 0 deletions ground-station/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@
<button id="cfe_tbl_noop" onclick="handle_command(this)">TBL No-Op</button>
<button id="cfe_time_noop" onclick="handle_command(this)">TIME No-Op</button>
<button id="cfe_es_noop" onclick="handle_command(this)">ES No-Op</button>
</br></br>
<button id="sample_toggle" onclick="handle_command(this)">Blink Baby!</button>
</body>
</html>
3 changes: 2 additions & 1 deletion ground-station/public/js/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ const args = {
cfe_sb_noop: { pktid: '0x1803' },
cfe_tbl_noop: { pktid: '0x1804' },
cfe_time_noop: { pktid: '0x1805' },
cfe_es_noop: { pktid: '0x1806' }
cfe_es_noop: { pktid: '0x1806' },
sample_toggle: { pktid: '0x1882', cmdcode: '3' }
}
2 changes: 1 addition & 1 deletion ground-station/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const express = require('express');
const morgan = require('morgan');

// app configuration
const DEBUG = true;
const DEBUG = false;
const REQUEST_DEBUG = false;
const node_port = 3000;
const node_env = process.env.NODE_ENV || 'development';
Expand Down

0 comments on commit b737f52

Please sign in to comment.