cc2530学习笔记

case KEY_CHANGE://按键事件

case AF_INCOMING_MSG_CMD://接收数据事件,调用函数AF_DataRequest()接收数据

case ZDO_STATE_CHANGE:
//只要网络状态发生改变,就通过ZDO_STATE_CHANGE事件通知所有的任务。
//同时完成对协调器,路由器,终端的设置

SAMPLEAPP_SEND_PERIODIC_MSG_EVT, //周期性事件处理函数
SAMPLEAPP_SEND_PERIODIC_MSG_TIMEOUT ); //每5s处理一次

case SAMPLEAPP_PERIODIC_CLUSTERID: //收到广播数据
case SAMPLEAPP_FLASH_CLUSTERID: //收到组播数据


//接收数据,参数为接收到的数据
void SampleApp_MessageMSGCB( afIncomingMSGPacket_t *pkt )

//分析发送周期信息
void SampleApp_SendPeriodicMessage( void )


/接收属于本应用任务SampleApp的消息,以SampleApp_TaskID标记
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( SampleApp_TaskID );

消息结构体:
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 */
uint8 nwkSeqNum; /* network header frame sequence number */
afMSGCommandFormat_t cmd; /* Application Data */
} afIncomingMSGPacket_t;

typedef struct
{
uint8 TransSeqNumber;
uint16 DataLength; // Number of bytes in TransData
uint8 *Data;
} afMSGCommandFormat_t;


event+簇id+消息内容+内容大小
MSGpkt->hdr.event + MSGpkt->clusterId + MSGpkt->cmd.Data + MSGpkt->cmd.DataLength


uint16 SampleApp_ProcessEvent( uint8 task_id, uint16 events )触发接收或者发送

开始消息----》判断事件AF_INCOMING_MSG_CMD----》处理函数----》SAMPLEAPP_PERIODIC_CLUSTERID簇ID

typedef enum
{
afAddrNotPresent = AddrNotPresent,
afAddr16Bit = Addr16Bit, //点播方式
afAddr64Bit = Addr64Bit,
afAddrGroup = AddrGroup, //组播方式
afAddrBroadcast = AddrBroadcast //广播方式
} afAddrMode_t;

typedef struct
{
union
{
uint16 shortAddr; //短地址
ZLongAddr_t extAddr; //IEEE地址
} addr;
afAddrMode_t addrMode; //传送模式
uint8 endPoint; //端点号
uint16 panId; // used for the INTER_PAN feature
} afAddrType_t;

afAddrType_t SampleApp_Periodic_DstAddr; //广播
afAddrType_t SampleApp_Flash_DstAddr; //组播
afAddrType_t SampleApp_P2P_DstAddr; //点播


SampleApp_Periodic_DstAddr.addrMode = (afAddrMode_t)AddrBroadcast;//广播
SampleApp_Periodic_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
SampleApp_Periodic_DstAddr.addr.shortAddr = 0xFFFF; //广播地址

// Setup for the flash command's destination address - Group 1
SampleApp_Flash_DstAddr.addrMode = (afAddrMode_t)afAddrGroup;//组播
SampleApp_Flash_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
SampleApp_Flash_DstAddr.addr.shortAddr = SAMPLEAPP_FLASH_GROUP;

SampleApp_P2P_DstAddr.addrMode = (afAddrMode_t)Addr16Bit; //点播
SampleApp_P2P_DstAddr.endPoint = SAMPLEAPP_ENDPOINT;
SampleApp_P2P_DstAddr.addr.shortAddr = 0x0000; //发给协调器 地址为0

原文地址:https://www.cnblogs.com/yihujiu/p/6020756.html