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 committed Feb 11, 2020
1 parent 90fcb47 commit 07fbad9
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_Global.HkBuf,
CFE_SB_InitMsg(&SAMPLE_Global.HkBuf.MsgHdr,
SAMPLE_APP_HK_TLM_MID,
sizeof(SAMPLE_Global.HkBuf),
true);
Expand Down Expand Up @@ -356,14 +356,14 @@ int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg )
/*
** Get command execution counters...
*/
SAMPLE_Global.HkBuf.Payload.CommandErrorCounter = SAMPLE_Global.ErrCounter;
SAMPLE_Global.HkBuf.Payload.CommandCounter = SAMPLE_Global.CmdCounter;
SAMPLE_Global.HkBuf.HkTlm.Payload.CommandErrorCounter = SAMPLE_Global.ErrCounter;
SAMPLE_Global.HkBuf.HkTlm.Payload.CommandCounter = SAMPLE_Global.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg((CFE_SB_Msg_t *) &SAMPLE_Global.HkBuf);
CFE_SB_SendMsg((CFE_SB_Msg_t *) &SAMPLE_Global.HkBuf);
CFE_SB_TimeStampMsg(&SAMPLE_Global.HkBuf.MsgHdr);
CFE_SB_SendMsg(&SAMPLE_Global.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 07fbad9

Please sign in to comment.