Home/Support/Support Forum/Problem with Packed struct in digi xbee ansi c library

Problem with Packed struct in digi xbee ansi c library

0 votes
Hi All.
I am porting the xbee ansi C library for STM32 platform. The problem i am facing is some of the struct that is defined as PACKED_STRUCT has members for instance a Union which are not packed and hence the compiler gives errors. If i __packed the Union then that might introduce bugs with un-aligned memory accesses. There are few structs that has this problems.

Ex: A struct declared in atcmd.h has a union xbee_at_cmd_t which is not packed.

typedef PACKED_STRUCT xbee_header_local_at_req {
/// #XBEE_FRAME_LOCAL_AT_CMD (0x08) or #XBEE_FRAME_LOCAL_AT_CMD_Q (0x09)
uint8_t frame_type;

/// 1 to 255, or 0 to suppress the Transmit Status response
uint8_t frame_id;

/// two-character AT Command
xbee_at_cmd_t command;
} xbee_header_local_at_req_t;

If i declare xbee_at_cmd_t as packed it will affect the code where it is no required.
What would be the best way around this issue.?
asked Jan 10 in DigiMesh Proprietary Mesh Networking by yafisdamda New to the Community (2 points)
Hi.
Without packing the structure it is sending padded(extra) bytes over serial line.
How come nobody had faced this problem.?

Please log in or register to answer this question.

...