微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI Zigbee设计交流 > match方式绑定的一些问题

match方式绑定的一些问题

时间:10-02 整理:3721RD 点击:

终端和协调器组网成功后,使用match方式进行绑定为什么实现不了,源代码如下:

终端:

Zigbee_end.c下:

GenericApp_Init中:ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp );//注册了Match_Desc_rsp

GenericApp_ProcessEvent中:switch(MSGpkt->hdr.event) {
                        case ZDO_CB_MSG:
                          GenericApp_ProcessZDOMsgs(( zdoIncomingMsg_t *)MSGpkt );
                          break;
                        case ZDO_STATE_CHANGE:
                                GenericApp_NwkState = (devStates_t)
                                        (MSGpkt->hdr.status);
                                if(GenericApp_NwkState == DEV_END_DEVICE) {
                                        // Start sending "the" message in
                                        // a regular interval.
                                        osal_set_event(GenericApp_TaskID,
                                                       ZIGBEE_SEND_EVENT);
                                        zb_BindDevice(TRUE, GENERICAPP_CLUSTERID, NULL);
                                }
                                break;

void zb_BindDevice ( uint8 create, uint16 commandId, uint8 *pDestination )
{  
  //#define ZB_INVALID_PARAMETER  0x02
  //#define ZSuccess  0x00
  //#define ZB_SUCCESS ZSuccess
  //#define ZB_ALREADY_IN_PROGRESS 0x20
  zAddrType_t destination;
  uint8 ret = ZB_ALREADY_IN_PROGRESS;
  static uint16 sapi_bindInProgress;

 
  if ( create )//如果为TRUE,创建绑定条目
  {
    if (sapi_bindInProgress == 0xffff)
    {
      if ( pDestination )//长地址不为空
      {
        //设置地址模式为64位长地址
        destination.addrMode = Addr64Bit;
        //将参数pDestination中的地址值复制到destination.addr.extAddr中
        osal_cpyExtAddr( destination.addr.extAddr, pDestination );
        //调用函数进行基于长地址的绑定
        ret = APSME_BindRequest( GenericApp_epDesc.endPoint, commandId,
                              &destination, GenericApp_epDesc.endPoint );
         
        if ( ret == ZSuccess )//0x00
        {
          //绑定成功后获取目的设备短地址
          ZDP_NwkAddrReq(pDestination, ZDP_ADDR_REQTYPE_SINGLE, 0, 0 );
          osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, 250 );
        }
      }
      else//长地址为空
      {
        ret = ZB_INVALID_PARAMETER;//0x02
        //设置地址模式为16位网络地址
        destination.addrMode = Addr16Bit;
        //设置目的短地址为0xFFFF,广播一个信号
        destination.addr.shortAddr = NWK_BROADCAST_SHORTADDR;
        //匹配一个允许绑定的设备
        ret = ZDP_MatchDescReq( &destination, NWK_BROADCAST_SHORTADDR,
                              GenericApp_epDesc.simpleDesc->AppProfId, 1, (cId_t*) GenericApp_ClusterList, 0, (cId_t*)NULL, 0 );
      
        if ( ret == ZB_SUCCESS )
        {
          //后续判断使用
          sapi_bindInProgress = commandId;
          return; // dont send cback event
        }
      }
    }
  }
}

ZDAPP.C下:

void GenericApp_ProcessZDOMsgs( zdoIncomingMsg_t *inMsg )
{
  switch ( inMsg->clusterID )
  {
   //确定是来自被绑定节点的响应
   case Match_Desc_rsp:
      {
        endPointDesc_t GenericApp_epDesc;
        static uint16 sapi_bindInProgress;
        zAddrType_t dstAddr;
        ZDO_ActiveEndpointRsp_t *pRsp = ZDO_ParseEPListRsp( inMsg ); 
        //sapi_bindInProgress在之前的程序中被修改为clusterID的值
        if ( sapi_bindInProgress != 0xffff )
        {
          //建立绑定表
          dstAddr.addrMode = Addr16Bit;
          dstAddr.addr.shortAddr = pRsp->nwkAddr;

          if ( APSME_BindRequest( GenericApp_epDesc.simpleDesc->EndPoint,
                     sapi_bindInProgress, &dstAddr, pRsp->epList[0] ) == ZSuccess )
          {
            ZLED1 = 1;//事实LED1并不亮
            //更新网络状态
            osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, 250 );
            //重新给sapi_bindInProgress赋值
            sapi_bindInProgress = 0xffff;
          }
        }
      }
   }
}

协调器:

Zigbee_coor.c下:

GenericApp_Init中afSetMatch(GenericApp_epDesc.simpleDesc->EndPoint, TRUE);//允许被匹配

其他配置不变

为什么终端在收到协调器的rsp后,不能点亮LED1?求大神指教~

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top