Skip to content

Commit

Permalink
Merge pull request #85 from jphickey/fix-19-use-msg-ptr
Browse files Browse the repository at this point in the history
Fix #19, Use CFE_MSG_PTR macro and other name updates
  • Loading branch information
dzbaker authored Mar 30, 2023
2 parents cdd47a6 + 4373781 commit 5554bd1
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 95 deletions.
59 changes: 39 additions & 20 deletions fsw/inc/lc_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,34 @@
*/

/**
* \brief No Arguments Command
* \brief Send HK Command
*
* For command details see #LC_NOOP_CC, #LC_RESET_CC
* Also see #LC_SEND_HK_MID
* For command details see #LC_SEND_HK_MID
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} LC_NoArgsCmd_t;
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */
} LC_SendHkCmd_t;

/**
* \brief No-op Command
*
* For command details see #LC_NOOP_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */
} LC_NoopCmd_t;

/**
* \brief Reset Counters Command
*
* For command details see #LC_RESET_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */
} LC_ResetCountersCmd_t;

/**
* \brief Set LC Application State Command
Expand All @@ -65,11 +84,11 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

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

/**
* \brief Set AP (Actionpoint) State Command
Expand All @@ -78,11 +97,11 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

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

/**
* \brief Set AP (Actionpoint) Permanently Off
Expand All @@ -91,11 +110,11 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

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

/**
* \brief Reset AP (Actionpoint) Statistics
Expand All @@ -104,11 +123,11 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

uint16 APNumber; /**< \brief Which actionpoint(s) to change */
uint16 Padding; /**< \brief Structure padding */
} LC_ResetAPStats_t;
} LC_ResetAPStatsCmd_t;

/**
* \brief Reset WP (Watchpoint) Statistics
Expand All @@ -117,11 +136,11 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

uint16 WPNumber; /**< \brief Which watchpoint(s) to change */
uint16 Padding; /**< \brief Structure padding */
} LC_ResetWPStats_t;
} LC_ResetWPStatsCmd_t;

/**
* \brief Sample AP (Actionpoint) Request
Expand All @@ -130,14 +149,14 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

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_t;
} LC_SampleAPCmd_t;

/**
* \brief Send Command to Start a Stored Command RTS
Expand All @@ -154,10 +173,10 @@ typedef struct
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command Header */

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

/**\}*/

Expand All @@ -171,7 +190,7 @@ typedef struct
*/
typedef struct
{
CFE_MSG_TelemetryHeader_t TlmHeader; /**< \brief Telemetry Header */
CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry Header */

uint8 CmdCount; /**< \brief LC Application Command Counter */
uint8 CmdErrCount; /**< \brief LC Application Command Error Counter */
Expand Down
14 changes: 7 additions & 7 deletions fsw/inc/lc_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
* Implements the Noop command that insures the LC task is alive
*
* \par Command Structure
* #LC_NoArgsCmd_t
* #LC_NoopCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -159,7 +159,7 @@
* Resets the LC housekeeping counters
*
* \par Command Structure
* #LC_NoArgsCmd_t
* #LC_ResetCountersCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -190,7 +190,7 @@
* Sets the operational state of the LC application
*
* \par Command Structure
* #LC_SetLCState_t
* #LC_SetLCStateCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -223,7 +223,7 @@
* Set actionpoint state
*
* \par Command Structure
* #LC_SetAPState_t
* #LC_SetAPStateCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -261,7 +261,7 @@
* Set the specified actionpoint's state to #LC_APSTATE_PERMOFF
*
* \par Command Structure
* #LC_SetAPPermOff_t
* #LC_SetAPPermOffCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -296,7 +296,7 @@
* Resets actionpoint statistics
*
* \par Command Structure
* #LC_ResetAPStats_t
* #LC_ResetAPStatsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -330,7 +330,7 @@
* Resets watchpoint statistics
*
* \par Command Structure
* #LC_ResetWPStats_t
* #LC_ResetWPStatsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down
3 changes: 2 additions & 1 deletion fsw/src/lc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ int32 LC_SbInit(void)
/*
** Initialize housekeeping packet...
*/
CFE_MSG_Init(&LC_OperData.HkPacket.TlmHeader.Msg, CFE_SB_ValueToMsgId(LC_HK_TLM_MID), sizeof(LC_HkPacket_t));
CFE_MSG_Init(CFE_MSG_PTR(LC_OperData.HkPacket.TelemetryHeader), CFE_SB_ValueToMsgId(LC_HK_TLM_MID),
sizeof(LC_HkPacket_t));

/*
** Create Software Bus message pipe...
Expand Down
68 changes: 38 additions & 30 deletions fsw/src/lc_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include "lc_platform_cfg.h"
#include "lc_utils.h"

#define LC_GET_CMD_PAYLOAD(ptr, type) ((const type *)(ptr))

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Process a command pipe message */
Expand Down Expand Up @@ -132,16 +134,18 @@ int32 LC_AppPipe(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SampleAPReq(const CFE_SB_Buffer_t *BufPtr)
{
LC_SampleAP_t *LC_SampleAP = (LC_SampleAP_t *)BufPtr;
size_t ExpectedLength = sizeof(LC_SampleAP_t);
uint16 WatchIndex;
bool ValidSampleCmd = false;
const LC_SampleAPCmd_t *LC_SampleAP;
size_t ExpectedLength = sizeof(LC_SampleAPCmd_t);
uint16 WatchIndex;
bool ValidSampleCmd = false;

/*
** Verify message packet length
*/
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
{
LC_SampleAP = LC_GET_CMD_PAYLOAD(BufPtr, LC_SampleAPCmd_t);

/*
** Ignore AP sample requests if disabled at the application level
*/
Expand Down Expand Up @@ -209,7 +213,7 @@ void LC_SampleAPReq(const CFE_SB_Buffer_t *BufPtr)
int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
{
int32 Result;
size_t ExpectedLength = sizeof(LC_NoArgsCmd_t);
size_t ExpectedLength = sizeof(LC_SendHkCmd_t);
uint16 TableIndex;
uint16 HKIndex;
uint8 ByteData;
Expand Down Expand Up @@ -477,8 +481,8 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
/*
** Timestamp and send housekeeping packet
*/
CFE_SB_TimeStampMsg(&LC_OperData.HkPacket.TlmHeader.Msg);
CFE_SB_TransmitMsg(&LC_OperData.HkPacket.TlmHeader.Msg, true);
CFE_SB_TimeStampMsg(CFE_MSG_PTR(LC_OperData.HkPacket.TelemetryHeader));
CFE_SB_TransmitMsg(CFE_MSG_PTR(LC_OperData.HkPacket.TelemetryHeader), true);

} /* end LC_VerifyMsgLength if */

Expand All @@ -494,7 +498,7 @@ int32 LC_HousekeepingReq(const CFE_MSG_CommandHeader_t *MsgPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_NoopCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_NoArgsCmd_t);
size_t ExpectedLength = sizeof(LC_NoopCmd_t);

/*
** Verify message packet length
Expand All @@ -517,7 +521,7 @@ void LC_NoopCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_ResetCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_NoArgsCmd_t);
size_t ExpectedLength = sizeof(LC_ResetCountersCmd_t);

/*
** Verify message packet length
Expand Down Expand Up @@ -557,15 +561,15 @@ void LC_ResetCounters(void)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SetLCStateCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_SetLCState_t);
LC_SetLCState_t *CmdPtr;
size_t ExpectedLength = sizeof(LC_SetLCStateCmd_t);
const LC_SetLCStateCmd_t *CmdPtr;

/*
** Verify message packet length
*/
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((LC_SetLCState_t *)BufPtr);
CmdPtr = LC_GET_CMD_PAYLOAD(BufPtr, LC_SetLCStateCmd_t);

switch (CmdPtr->NewLCState)
{
Expand Down Expand Up @@ -598,19 +602,19 @@ void LC_SetLCStateCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SetAPStateCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_SetAPState_t);
LC_SetAPState_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;
bool ValidState = true;
bool CmdSuccess = false;
size_t ExpectedLength = sizeof(LC_SetAPStateCmd_t);
const LC_SetAPStateCmd_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;
bool ValidState = true;
bool CmdSuccess = false;

/*
** Verify message packet length
*/
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((LC_SetAPState_t *)BufPtr);
CmdPtr = LC_GET_CMD_PAYLOAD(BufPtr, LC_SetAPStateCmd_t);

/*
** Do a sanity check on the new actionpoint state
Expand Down Expand Up @@ -728,17 +732,17 @@ void LC_SetAPStateCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_SetAPPermOffCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_SetAPPermOff_t);
LC_SetAPPermOff_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;
size_t ExpectedLength = sizeof(LC_SetAPPermOffCmd_t);
const LC_SetAPPermOffCmd_t *CmdPtr;
uint32 TableIndex;
uint8 CurrentAPState;

/*
** Verify message packet length
*/
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = ((LC_SetAPPermOff_t *)BufPtr);
CmdPtr = LC_GET_CMD_PAYLOAD(BufPtr, LC_SetAPPermOffCmd_t);

if (((CmdPtr->APNumber) == LC_ALL_ACTIONPOINTS) || ((CmdPtr->APNumber) >= LC_MAX_ACTIONPOINTS))
{
Expand Down Expand Up @@ -795,13 +799,15 @@ void LC_SetAPPermOffCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_ResetAPStatsCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_ResetAPStats_t);
LC_ResetAPStats_t *CmdPtr = (LC_ResetAPStats_t *)BufPtr;
bool CmdSuccess = false;
size_t ExpectedLength = sizeof(LC_ResetAPStatsCmd_t);
const LC_ResetAPStatsCmd_t *CmdPtr;
bool CmdSuccess = false;

/* verify message packet length */
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = LC_GET_CMD_PAYLOAD(BufPtr, LC_ResetAPStatsCmd_t);

/* arg may be one or all AP's */
if (CmdPtr->APNumber == LC_ALL_ACTIONPOINTS)
{
Expand Down Expand Up @@ -873,13 +879,15 @@ void LC_ResetResultsAP(uint32 StartIndex, uint32 EndIndex, bool ResetStatsCmd)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void LC_ResetWPStatsCmd(const CFE_SB_Buffer_t *BufPtr)
{
size_t ExpectedLength = sizeof(LC_ResetWPStats_t);
LC_ResetWPStats_t *CmdPtr = (LC_ResetWPStats_t *)BufPtr;
bool CmdSuccess = false;
size_t ExpectedLength = sizeof(LC_ResetWPStatsCmd_t);
const LC_ResetWPStatsCmd_t *CmdPtr;
bool CmdSuccess = false;

/* verify message packet length */
if (LC_VerifyMsgLength(&BufPtr->Msg, ExpectedLength))
{
CmdPtr = LC_GET_CMD_PAYLOAD(BufPtr, LC_ResetWPStatsCmd_t);

/* arg may be one or all WP's */
if (CmdPtr->WPNumber == LC_ALL_WATCHPOINTS)
{
Expand Down
Loading

0 comments on commit 5554bd1

Please sign in to comment.