Skip to content

Commit

Permalink
Fix #38: Add union for proper TLM buffer alignment
Browse files Browse the repository at this point in the history
Put the HkTlm buffer into a union to ensure it is aligned
appropriately for conversion to a CFE_SB_Msg_t type.
  • Loading branch information
jphickey authored and astrogeco committed Mar 9, 2020
1 parent 4adabae commit 1db3d97
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
10 changes: 5 additions & 5 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int32 SAMPLE_AppInit( void )
/*
** Initialize housekeeping packet (clear user data area).
*/
CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf,
CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf.MsgHdr,
SAMPLE_APP_HK_TLM_MID,
sizeof(SAMPLE_AppData.HkBuf),
true);
Expand Down Expand Up @@ -356,14 +356,14 @@ int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )
/*
** Get command execution counters...
*/
SAMPLE_AppData.HkBuf.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter;
SAMPLE_AppData.HkBuf.Payload.CommandCounter = SAMPLE_AppData.CmdCounter;
SAMPLE_AppData.HkBuf.HkTlm.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter;
SAMPLE_AppData.HkBuf.HkTlm.Payload.CommandCounter = SAMPLE_AppData.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkBuf);
CFE_SB_SendMsg(&SAMPLE_AppData.HkBuf);
CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkBuf.MsgHdr);
CFE_SB_SendMsg(&SAMPLE_AppData.HkBuf.MsgHdr);

/*
** Manage any pending table loads, validations, etc.
Expand Down
13 changes: 12 additions & 1 deletion fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@
/************************************************************************
** Type Definitions
*************************************************************************/

/*
* Buffer to hold telemetry data prior to sending
* Defined as a union to ensure proper alignment for a CFE_SB_Msg_t type
*/
typedef union
{
CFE_SB_Msg_t MsgHdr;
SAMPLE_HkTlm_t HkTlm;
} SAMPLE_HkBuffer_t;

/*
** Global Data
*/
Expand All @@ -70,7 +81,7 @@ typedef struct
/*
** Housekeeping telemetry packet...
*/
SAMPLE_HkTlm_t HkBuf;
SAMPLE_HkBuffer_t HkBuf;

/*
** Run Status variable used in the main processing loop
Expand Down

0 comments on commit 1db3d97

Please sign in to comment.