Z-stack数据接收问题

任务接收信息配置

在API文档中介绍了这个函数ZDO_RegistorForZDOMsg(),应用程序调用这个函数登记信息就能接收任何无线信息。

接收此信息的task可以自己解析数据,也可以调用ZDO里面的解析函数来解析。

prototype

ZStatus_t ZDO_RegisterForZDOMsg( uint8 taskID, uint16 clusterID )

taskID    应用程序的ID,OSAL发送的任务ID

clusterID  需要接收信息的簇ID

返回值

状态值 success or error

读一个函数首先读的是它的数据结构,其次才是实现算法。在这里面我们首先看到的数据结构是:

typedef struct
{
  void *next;
  uint8 taskID;
  uint16 clusterID;
} ZDO_MsgCB_t;

这就是一个taskID和clusterID的结构体形成的链表*next指向一个ZDO_MsgCB_t结构体。程序先遍历链表,已经注册了就返回success,没注册就注册到最后面,形成新的链表。

数据接收

接收到信息后,将触发sys_event_msg,并对AF_INCOMING_MSG_COM信息进行处理。在SYS_EVENT事件中,操作系统,对AF_INCOMING_MSG_CMD进行处理,

  if ( events & SYS_EVENT_MSG )
  {
    pMsg = (osal_event_hdr_t *) osal_msg_receive( task_id );
    while ( pMsg )
    {
      switch ( pMsg->event )
      {
        case ZDO_CB_MSG:
          SAPI_ProcessZDOMsgs( (zdoIncomingMsg_t *)pMsg );
          break;

        case AF_DATA_CONFIRM_CMD:
          // This message is received as a confirmation of a data packet sent.
          // The status is of ZStatus_t type [defined in ZComDef.h]
          // The message fields are defined in AF.h
          pDataConfirm = (afDataConfirm_t *) pMsg;
          SAPI_SendDataConfirm( pDataConfirm->transID, pDataConfirm->hdr.status );
          break;

        case AF_INCOMING_MSG_CMD:
          pMSGpkt = (afIncomingMSGPacket_t *) pMsg;
          SAPI_ReceiveDataIndication( pMSGpkt->srcAddr.addr.shortAddr, pMSGpkt->clusterId,
                                    pMSGpkt->cmd.DataLength, pMSGpkt->cmd.Data);
          break;

void SAPI_ReceiveDataIndication( uint16 source, uint16 command, uint16 len, uint8 *pData  )
{
#if defined ( MT_SAPI_CB_FUNC )
  /* First check if MT has subscribed for this callback. If so , pass it as
  a event to MonitorTest and return control to calling function after that */
  if ( SAPICB_CHECK( SPI_CB_SAPI_RCV_DATA_IND ) )
  {
    zb_MTCallbackReceiveDataIndication( source, command, len, pData  );
  }
  else
#endif  //MT_SAPI_CB_FUNC
  {
    zb_ReceiveDataIndication( source, command, len, pData  );
  }
}

最后调用的zb_ReceiveDataIndication()对接收到的数据进行指示。这个函数又用户自己的填写。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值