关于z-stack结构体默认对齐方式与强制转换问题,急,求大神回答
z-stack的结构体默认对齐方式是一字节吗?
在z-stack中可以将一般指针强制转换为结构体指针吗?
2530是单字节, 2538是四字节对齐。
你说的指针可以强转。
搞不懂以下这两个结构体为什么可以转换
uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events ) { afIncomingMSGPacket_t * MSGpkt; if ( events & SYS_EVENT_MSG ) { MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID ); while ( MSGpkt ) { switch ( MSGpkt->hdr.event ) { case KEY_CHANGE: SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys ); break; 1 typedef struct { osal_event_hdr_t hdr; uint8 state; // shift uint8 keys; // keys } keyChange_t; typedef struct { osal_event_hdr_t hdr; /* OSAL Message header */ uint16 groupId; /* Message's group ID - 0 if not set */ uint16 clusterId; /* Message's cluster ID */ afAddrType_t srcAddr; /* Source Address, if endpoint is STUBAPS_INTER_PAN_EP, it's an InterPAN message */ uint16 macDestAddr; /* MAC header destination short address */ uint8 endPoint; /* destination endpoint */ uint8 wasBroadcast; /* TRUE if network destination was a broadcast address */ uint8 LinkQuality; /* The link quality of the received data frame */ uint8 correlation; /* The raw correlation value of the received data frame */ int8 rssi; /* The received RF power in units dBm */ uint8 SecurityUse; /* deprecated */ uint32 timestamp; /* receipt timestamp from MAC */ afMSGCommandFormat_t cmd; /* Application Data */ } afIncomingMSGPacket_t;
两个结构体的成员不一样啊,会不会访问出错的?
消息头一直,第一次转换 一般只取消息头信息
可以不可以这样理解:
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );这个条语句只是接收到一个消息,还不知道是什么消息
switch
( MSGpkt->hdr.event )
{
case
KEY_CHANGE: //这里发现是一条按键消息,
SampleApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
那么上面接收到的消息的内容就是
typedef
struct
{
osal_event_hdr_t hdr;
uint8 state;
// shift
uint8 keys;
// keys
} keyChange_t;
这个结构体的内容,如果按照
typedef
struct
{
osal_event_hdr_t hdr;
/* OSAL Message header */
uint16 groupId;
/* Message's group ID - 0 if not set */
uint16 clusterId;
/* Message's cluster ID */
afAddrType_t srcAddr;
/* Source Address, if endpoint is STUBAPS_INTER_PAN_EP,
it's an InterPAN message */
uint16 macDestAddr;
/* MAC header destination short address */
uint8 endPoint;
/* destination endpoint */
uint8 wasBroadcast;
/* TRUE if network destination was a broadcast address */
uint8 LinkQuality;
/* The link quality of the received data frame */
uint8 correlation;
/* The raw correlation value of the received data frame */
int8 rssi;
/* The received RF power in units dBm */
uint8 SecurityUse;
/* deprecated */
uint32 timestamp;
/* receipt timestamp from MAC */
afMSGCommandFormat_t cmd;
/* Application Data */
} afIncomingMSGPacket_t;
这个结构体访问的话,其实中的uint16 groupId;就是
uint8 state;
// shift
uint8 keys;
// keys
这两个变量的值?