Skip to content

Commit

Permalink
Fix #81, use payload sub-structure
Browse files Browse the repository at this point in the history
Put all cmd/tlm message content in a sub-structure named "Payload"
  • Loading branch information
jphickey committed Mar 31, 2023
1 parent 5554bd1 commit c734b84
Show file tree
Hide file tree
Showing 7 changed files with 456 additions and 322 deletions.
116 changes: 96 additions & 20 deletions fsw/inc/lc_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ typedef struct
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */
} LC_ResetCountersCmd_t;

/**
* \brief Set LC Application State Payload
*
* For command details see #LC_SET_LC_STATE_CC
*/
typedef struct
{
uint16 NewLCState; /**< \brief New LC application state */
uint16 Padding; /**< \brief Structure padding */
} LC_SetLCState_Payload_t;

/**
* \brief Set LC Application State Command
*
Expand All @@ -86,10 +97,20 @@ typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

uint16 NewLCState; /**< \brief New LC application state */
uint16 Padding; /**< \brief Structure padding */
LC_SetLCState_Payload_t Payload;
} LC_SetLCStateCmd_t;

/**
* \brief Set AP (Actionpoint) State Payload
*
* For command details see #LC_SET_AP_STATE_CC
*/
typedef struct
{
uint16 APNumber; /**< \brief Which actionpoint(s) to change */
uint16 NewAPState; /**< \brief New actionpoint state */
} LC_SetAPState_Payload_t;

/**
* \brief Set AP (Actionpoint) State Command
*
Expand All @@ -99,65 +120,112 @@ typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

uint16 APNumber; /**< \brief Which actionpoint(s) to change */
uint16 NewAPState; /**< \brief New actionpoint state */
LC_SetAPState_Payload_t Payload;
} LC_SetAPStateCmd_t;

/**
* \brief Set AP (Actionpoint) Permanently Off
* \brief Set AP (Actionpoint) Permanently Off Payload
*
* For command details see #LC_SET_AP_PERM_OFF_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

uint16 APNumber; /**< \brief Which actionpoint to change */
uint16 Padding; /**< \brief Structure padding */
} LC_SetAPPermOffCmd_t;
} LC_SetAPPermOff_Payload_t;

/**
* \brief Reset AP (Actionpoint) Statistics
* \brief Set AP (Actionpoint) Permanently Off Command
*
* For command details see #LC_RESET_AP_STATS_CC
* For command details see #LC_SET_AP_PERM_OFF_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

LC_SetAPPermOff_Payload_t Payload;
} LC_SetAPPermOffCmd_t;

/**
* \brief Reset AP (Actionpoint) Statistics Payload
*
* For command details see #LC_RESET_AP_STATS_CC
*/
typedef struct
{
uint16 APNumber; /**< \brief Which actionpoint(s) to change */
uint16 Padding; /**< \brief Structure padding */
} LC_ResetAPStatsCmd_t;
} LC_ResetAPStats_Payload_t;

/**
* \brief Reset WP (Watchpoint) Statistics
* \brief Reset AP (Actionpoint) Statistics Command
*
* For command details see #LC_RESET_WP_STATS_CC
* For command details see #LC_RESET_AP_STATS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

LC_ResetAPStats_Payload_t Payload;
} LC_ResetAPStatsCmd_t;

/**
* \brief Reset WP (Watchpoint) Statistics Payload
*
* For command details see #LC_RESET_WP_STATS_CC
*/
typedef struct
{
uint16 WPNumber; /**< \brief Which watchpoint(s) to change */
uint16 Padding; /**< \brief Structure padding */
} LC_ResetWPStatsCmd_t;
} LC_ResetWPStats_Payload_t;

/**
* \brief Sample AP (Actionpoint) Request
* \brief Reset WP (Watchpoint) Statistics Command
*
* See #LC_SAMPLE_AP_MID
* For command details see #LC_RESET_WP_STATS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

LC_ResetWPStats_Payload_t Payload;
} LC_ResetWPStatsCmd_t;

/**
* \brief Sample AP (Actionpoint) Payload
*
* See #LC_SAMPLE_AP_MID
*/
typedef struct
{
uint16 StartIndex; /**< \brief Start actionpoint to sample */
uint16 EndIndex; /**< \brief End actionpoint to sample */

uint16 UpdateAge; /**< \brief Update WP results age (T or F) */
uint16 Padding; /**< \brief Structure padding */
} LC_SampleAP_Payload_t;

/**
* \brief Sample AP (Actionpoint) Request
*
* See #LC_SAMPLE_AP_MID
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

LC_SampleAP_Payload_t Payload;
} LC_SampleAPCmd_t;

/**
* \brief Payload to Start a Stored Command RTS
*/
typedef struct
{
uint16 RTSId; /**< \brief RTS Id to start */
} LC_RTSRequest_Payload_t;

/**
* \brief Send Command to Start a Stored Command RTS
*
Expand All @@ -175,7 +243,7 @@ typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

uint16 RTSId; /**< \brief RTS Id to start */
LC_RTSRequest_Payload_t Payload;
} LC_RTSRequestCmd_t;

/**\}*/
Expand All @@ -186,12 +254,10 @@ typedef struct
*/

/**
* \brief Housekeeping Packet Structure
* \brief Housekeeping Payload Structure
*/
typedef struct
{
CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry Header */

uint8 CmdCount; /**< \brief LC Application Command Counter */
uint8 CmdErrCount; /**< \brief LC Application Command Error Counter */
uint8 CurrentLCState; /**< \brief Current LC application operating state */
Expand All @@ -214,6 +280,16 @@ typedef struct
uint32 APSampleCount; /**< \brief Total count of Actionpoints sampled */
uint32 MonitoredMsgCount; /**< \brief Total count of messages monitored for watchpoints */
uint32 RTSExecCount; /**< \brief Total count of RTS sequences initiated */
} LC_HkTlm_Payload_t;

/**
* \brief Housekeeping Telemetry Structure Structure
*/
typedef struct
{
CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry Header */

LC_HkTlm_Payload_t Payload;
} LC_HkPacket_t;

/**\}*/
Expand Down
80 changes: 42 additions & 38 deletions fsw/src/lc_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "lc_platform_cfg.h"
#include "lc_utils.h"

#define LC_GET_CMD_PAYLOAD(ptr, type) ((const type *)(ptr))
#define LC_GET_CMD_PAYLOAD(ptr, type) (&((const type *)(ptr))->Payload)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
Expand Down Expand Up @@ -80,7 +80,7 @@ int32 LC_AppPipe(const CFE_SB_Buffer_t *BufPtr)
break;

case LC_RESET_CC:
LC_ResetCmd(BufPtr);
LC_ResetCountersCmd(BufPtr);
break;

case LC_SET_LC_STATE_CC:
Expand Down Expand Up @@ -134,10 +134,10 @@ int32 LC_AppPipe(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SampleAPReq(const CFE_SB_Buffer_t *BufPtr)
{
const LC_SampleAPCmd_t *LC_SampleAP;
size_t ExpectedLength = sizeof(LC_SampleAPCmd_t);
uint16 WatchIndex;
bool ValidSampleCmd = false;
const LC_SampleAP_Payload_t *LC_SampleAP;
size_t ExpectedLength = sizeof(LC_SampleAPCmd_t);
uint16 WatchIndex;
bool ValidSampleCmd = false;

/*
** Verify message packet length
Expand Down Expand Up @@ -218,6 +218,8 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
uint16 HKIndex;
uint8 ByteData;

LC_HkTlm_Payload_t *PayloadPtr;

/*
** Verify message packet length
*/
Expand All @@ -226,20 +228,22 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
/*
** Update HK variables
*/
LC_OperData.HkPacket.CmdCount = LC_AppData.CmdCount;
LC_OperData.HkPacket.CmdErrCount = LC_AppData.CmdErrCount;
LC_OperData.HkPacket.APSampleCount = LC_AppData.APSampleCount;
LC_OperData.HkPacket.MonitoredMsgCount = LC_AppData.MonitoredMsgCount;
LC_OperData.HkPacket.RTSExecCount = LC_AppData.RTSExecCount;
LC_OperData.HkPacket.PassiveRTSExecCount = LC_AppData.PassiveRTSExecCount;
LC_OperData.HkPacket.CurrentLCState = LC_AppData.CurrentLCState;
LC_OperData.HkPacket.WPsInUse = LC_OperData.WatchpointCount;
PayloadPtr = &LC_OperData.HkPacket.Payload;

PayloadPtr->CmdCount = LC_AppData.CmdCount;
PayloadPtr->CmdErrCount = LC_AppData.CmdErrCount;
PayloadPtr->APSampleCount = LC_AppData.APSampleCount;
PayloadPtr->MonitoredMsgCount = LC_AppData.MonitoredMsgCount;
PayloadPtr->RTSExecCount = LC_AppData.RTSExecCount;
PayloadPtr->PassiveRTSExecCount = LC_AppData.PassiveRTSExecCount;
PayloadPtr->CurrentLCState = LC_AppData.CurrentLCState;
PayloadPtr->WPsInUse = LC_OperData.WatchpointCount;

/*
** Clear out the active actionpoint count, it will get
** recomputed below
*/
LC_OperData.HkPacket.ActiveAPs = 0;
PayloadPtr->ActiveAPs = 0;

/*
** Update packed watch results
Expand Down Expand Up @@ -348,7 +352,7 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
/*
** Update houskeeping watch results array
*/
LC_OperData.HkPacket.WPResults[HKIndex] = ByteData;
PayloadPtr->WPResults[HKIndex] = ByteData;

} /* end watch results for loop */

Expand All @@ -371,7 +375,7 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)

case LC_APSTATE_ACTIVE:
ByteData = LC_HKAR_STATE_ACTIVE << 6;
LC_OperData.HkPacket.ActiveAPs++;
PayloadPtr->ActiveAPs++;
break;

case LC_APSTATE_PASSIVE:
Expand Down Expand Up @@ -431,7 +435,7 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)

case LC_APSTATE_ACTIVE:
ByteData = (ByteData | (LC_HKAR_STATE_ACTIVE << 2));
LC_OperData.HkPacket.ActiveAPs++;
PayloadPtr->ActiveAPs++;
break;

case LC_APSTATE_PASSIVE:
Expand Down Expand Up @@ -474,7 +478,7 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
/*
** Update houskeeping action results array
*/
LC_OperData.HkPacket.APResults[HKIndex] = ByteData;
PayloadPtr->APResults[HKIndex] = ByteData;

} /* end action results for loop */

Expand Down Expand Up @@ -519,7 +523,7 @@ void LC_NoopCmd(const CFE_SB_Buffer_t *BufPtr)
/* Reset counters command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_ResetCmd(const CFE_SB_Buffer_t *BufPtr)
void LC_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_ResetCountersCmd_t);

Expand Down Expand Up @@ -561,8 +565,8 @@ void LC_ResetCounters(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SetLCStateCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_SetLCStateCmd_t);
const LC_SetLCStateCmd_t *CmdPtr;
size_t ExpectedLength = sizeof(LC_SetLCStateCmd_t);
const LC_SetLCState_Payload_t *CmdPtr;

/*
** Verify message packet length
Expand Down Expand Up @@ -602,12 +606,12 @@ void LC_SetLCStateCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SetAPStateCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_SetAPStateCmd_t);
const LC_SetAPStateCmd_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;
bool ValidState = true;
bool CmdSuccess = false;
size_t ExpectedLength = sizeof(LC_SetAPStateCmd_t);
const LC_SetAPState_Payload_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;
bool ValidState = true;
bool CmdSuccess = false;

/*
** Verify message packet length
Expand Down Expand Up @@ -732,10 +736,10 @@ void LC_SetAPStateCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SetAPPermOffCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_SetAPPermOffCmd_t);
const LC_SetAPPermOffCmd_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;
size_t ExpectedLength = sizeof(LC_SetAPPermOffCmd_t);
const LC_SetAPPermOff_Payload_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;

/*
** Verify message packet length
Expand Down Expand Up @@ -799,9 +803,9 @@ void LC_SetAPPermOffCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_ResetAPStatsCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_ResetAPStatsCmd_t);
const LC_ResetAPStatsCmd_t *CmdPtr;
bool CmdSuccess = false;
size_t ExpectedLength = sizeof(LC_ResetAPStatsCmd_t);
const LC_ResetAPStats_Payload_t *CmdPtr;
bool CmdSuccess = false;

/* verify message packet length */
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
Expand Down Expand Up @@ -879,9 +883,9 @@ void LC_ResetResultsAP(uint32 StartIndex, uint32 EndIndex, bool ResetStatsCmd)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_ResetWPStatsCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_ResetWPStatsCmd_t);
const LC_ResetWPStatsCmd_t *CmdPtr;
bool CmdSuccess = false;
size_t ExpectedLength = sizeof(LC_ResetWPStatsCmd_t);
const LC_ResetWPStats_Payload_t *CmdPtr;
bool CmdSuccess = false;

/* verify message packet length */
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
Expand Down
Loading

0 comments on commit c734b84

Please sign in to comment.