⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zdobject.c

📁 Zigbee2006入门(源代码+文档讲解+系统推荐)
💻 C
📖 第 1 页 / 共 5 页
字号:
#endif // ZDO_NWKADDR_REQUEST ZDO_IEEEADDR_REQUEST

#if defined ( ZDO_NODEDESC_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessNodeDescRsp
 *
 * @brief       This function processes and responds to the
 *              Node_Desc_rsp message.
 *
 * @param       SrcAddr  - Source address
 * @param       msg - input message containing search material
 *
 * @return      none
 */
void ZDO_ProcessNodeDescRsp( zAddrType_t *SrcAddr, byte *msg )
{
  byte proVer = NLME_GetProtocolVersion();
  NodeDescriptorFormat_t nodeDesc;
  NodeDescriptorFormat_t *pNodeDesc = NULL;
  byte Status = *msg++;
  uint16 aoi = BUILD_UINT16( msg[0], msg[1] );

  if ( Status == ZDP_SUCCESS )
  {
    msg += 2;
    nodeDesc.LogicalType = *msg & 0x07;
    if ( proVer == ZB_PROT_V1_0 )
    {
      nodeDesc.UserDescAvail = 0;
      nodeDesc.ComplexDescAvail = 0;
    }
    else
    {
      nodeDesc.ComplexDescAvail = ( *msg & 0x08 ) >> 3;
      nodeDesc.UserDescAvail = ( *msg & 0x10 ) >> 4;
    }
    msg++;  // Reserved bits.
    nodeDesc.FrequencyBand = (*msg >> 3) & 0x1f;
    nodeDesc.APSFlags = *msg++ & 0x07;
    nodeDesc.CapabilityFlags = *msg++;
    nodeDesc.ManufacturerCode[0] = *msg++;
    nodeDesc.ManufacturerCode[1] = *msg++;
    nodeDesc.MaxBufferSize = *msg++;
    nodeDesc.MaxTransferSize[0] = *msg++;
    nodeDesc.MaxTransferSize[1] = *msg++;
    
    if ( proVer == ZB_PROT_V1_0)
    {
      nodeDesc.ServerMask = 0;
    }
    else
    {
      nodeDesc.ServerMask = BUILD_UINT16( msg[0], msg[1] );
    }
    
    pNodeDesc = &nodeDesc;
  }

  ZDApp_NodeDescRspCB( SrcAddr, Status, aoi, pNodeDesc );
}
#endif // ZDO_NODEDESC_REQUEST

#if defined ( ZDO_POWERDESC_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessPowerDescRsp
 *
 * @brief       This function processes and responds to the
 *              Power_Desc_rsp message.
 *
 * @param       SrcAddr  - Source address
 * @param       msg - input message containing search material
 *
 * @return      none
 */
void ZDO_ProcessPowerDescRsp( zAddrType_t *SrcAddr, byte *msg )
{
  NodePowerDescriptorFormat_t pwrDesc;
  NodePowerDescriptorFormat_t *pPwrDesc = NULL;
  byte Status = *msg++;
  uint16 aoi = BUILD_UINT16( msg[0], msg[1] );

  if ( Status == ZDP_SUCCESS )
  {
    msg += 2;
    pwrDesc.AvailablePowerSources = *msg >> 4;
    pwrDesc.PowerMode = *msg++ & 0x0F;
    pwrDesc.CurrentPowerSourceLevel = *msg >> 4;
    pwrDesc.CurrentPowerSource = *msg++ & 0x0F;
    pPwrDesc = &pwrDesc;
  }

  ZDApp_PowerDescRspCB( SrcAddr, Status, aoi, pPwrDesc );
}
#endif // ZDO_POWERDESC_REQUEST

#if defined ( ZDO_SIMPLEDESC_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessSimpleDescRsp
 *
 * @brief       This function processes and responds to the
 *              Simple_Desc_rsp message.
 *
 * @param       SrcAddr  - Source address
 * @param       msg - input message containing search material
 *
 * @return      none
 */
void ZDO_ProcessSimpleDescRsp( zAddrType_t *SrcAddr, byte *msg )
{
  byte epIntf = 0;
  SimpleDescriptionFormat_t simpleDesc;
  SimpleDescriptionFormat_t *pSimpleDesc = NULL;
  byte Status = *msg++;
  uint16 aoi = BUILD_UINT16( msg[0], msg[1] );

  if ( Status == ZDP_SUCCESS )
  {
    msg += 3;
    epIntf = *msg;
    pSimpleDesc = &simpleDesc;
    ZDO_ParseSimpleDescBuf( msg, pSimpleDesc );
  }

  ZDApp_SimpleDescRspCB( SrcAddr, Status, aoi, epIntf, pSimpleDesc );
}
#endif // ZDO_SIMPLEDESC_REQUEST

#if defined ( ZDO_ACTIVEEP_REQUEST ) || defined ( ZDO_MATCH_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessEPListRsp
 *
 * @brief       This function processes and responds to the
 *              Active_EP_rsp or Match_Desc_rsp message.
 *
 * @param       src  - Source address
 * @param       ClusterID - Active_EP_rsp or Match_Desc_rsp
 * @param       msg - input message containing search material
 *
 * @return      none
 */
void ZDO_ProcessEPListRsp( zAddrType_t *src, uint16 ClusterID, byte *msg )
{
  byte Status = *msg++;
  byte cnt = msg[2];
  byte *list = msg+3;

  src->addr.shortAddr = BUILD_UINT16( msg[0], msg[1] );

#if defined ( ZDO_ACTIVEEP_REQUEST )
  if ( ClusterID == Active_EP_rsp )
    ZDApp_ActiveEPRspCB( src, Status, cnt, list );
#endif

#if defined ( ZDO_MATCH_REQUEST )
  if ( ClusterID == Match_Desc_rsp )
    ZDApp_MatchDescRspCB( src, Status, cnt, list );
#endif
}
#endif  // ZDO_ACTIVEEP_REQUEST ZDO_MATCH_REQUEST

#if defined ( ZDO_BIND_UNBIND_REQUEST ) || defined ( ZDO_ENDDEVICEBIND_REQUEST ) || defined ( ZDO_COORDINATOR )
/*********************************************************************
 * @fn          ZDO_ProcessBindUnBindRsp
 *
 * @brief       This function processes and responds to the
 *              End_Device_Bind_rsp message.
 *
 * @param       SrcAddr  - Source address
 * @param       ClusterID - Active_EP_rsp or Match_Desc_rsp
 * @param       msg - input message containing search material
 *
 * @return      none
 */
void ZDO_ProcessBindUnbindRsp( zAddrType_t *SrcAddr, uint16 ClusterID, byte Status, uint8 TransSeq )
{
#if defined ( ZDO_COORDINATOR )
  uint8 used = FALSE;
#endif

#if defined ( ZDO_ENDDEVICEBIND_REQUEST )
  if ( ClusterID == End_Device_Bind_rsp )
    ZDApp_EndDeviceBindRsp( SrcAddr, Status );
#endif

#if defined ( ZDO_COORDINATOR )
  if ( matchED )
  {
    used = ZDMatchSendState(
           (uint8)((ClusterID == Bind_rsp) ? ZDMATCH_REASON_BIND_RSP : ZDMATCH_REASON_UNBIND_RSP),
           Status, TransSeq );
  }

  if ( !used )
#endif
  {
  #if defined ( ZDO_BIND_UNBIND_REQUEST )
    if ( ClusterID == Bind_rsp )
      ZDApp_BindRsp( SrcAddr, Status );
    else
      ZDApp_UnbindRsp( SrcAddr, Status );
  #endif
  }
}
#endif // ZDO_BIND_UNBIND_REQUEST ZDO_ENDDEVICEBIND_REQUEST

#if defined ( ZDO_SERVERDISC_REQUEST )
/*********************************************************************
 * @fn          ZDO_ProcessServerDiscRsp
 *
 * @brief       Process the Server_Discovery_rsp message.
 *
 * @param       srcAddr - Source address.
 * @param       msg - Byte array containing the Server_Discovery_rsp command frame.
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessServerDiscRsp(zAddrType_t *srcAddr, byte *msg, byte SecurityUse)
{
  byte status = *msg++;
  uint16 serverMask = BUILD_UINT16( msg[0], msg[1] );

  ZDApp_ServerDiscRspCB( srcAddr->addr.shortAddr, status, serverMask,
                         SecurityUse );
}
#endif

#if defined ( ZDO_SERVERDISC_RESPONSE )
/*********************************************************************
 * @fn          ZDO_ProcessServerDiscReq
 *
 * @brief       Process the Server_Discovery_req message.
 *
 * @param       transID - Transaction sequence number of request.
 * @param       srcAddr  - Source address
 * @param       msg - Byte array containing the Server_Discovery_req command frame.
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessServerDiscReq( byte transID, zAddrType_t *srcAddr, byte *msg,
                               byte SecurityUse )
{
  uint16 serverMask = BUILD_UINT16( msg[0], msg[1] );
  uint16 matchMask = serverMask & ZDO_Config_Node_Descriptor.ServerMask;

  if ( matchMask )
  {
    ZDP_ServerDiscRsp( transID, srcAddr, ZSUCCESS, ZDAppNwkAddr.addr.shortAddr,
                       matchMask, SecurityUse );
  }
}
#endif

/*********************************************************************
 * Call Back Functions from APS  - API
 */

/*********************************************************************
 * @fn          ZDO_EndDeviceTimeoutCB
 *
 * @brief       This function handles the binding timer for the End
 *              Device Bind command.
 *
 * @param       none
 *
 * @return      none
 */
void ZDO_EndDeviceTimeoutCB( void )
{
#if defined ( REFLECTOR )
  byte stat;
  if ( ZDO_EDBind )
  {
    stat = ZDO_EDBind->status;

    // Send the response message to the first sent
    ZDO_SendEDBindRsp( ZDO_EDBind->SrcTransSeq, &(ZDO_EDBind->SrcAddr),
                        stat, ZDO_EDBind->SecurityUse );

    ZDO_RemoveEndDeviceBind();
  }
#endif  // REFLECTOR
}

/*********************************************************************
 * Optional Management Messages
 */

#if defined( ZDO_MGMT_LQI_RESPONSE ) && defined ( RTR_NWK )
/*********************************************************************
 * @fn          ZDO_ProcessMgmtLqiReq
 *
 * @brief       This function handles parsing the incoming Management
 *              LQI request and generate the response.
 *
 *   Note:      This function will limit the number of items returned
 *              to ZDO_MAX_LQI_ITEMS items.
 *
 * @param       SrcAddr - source of the request
 * @param       StartIndex - where to start the return list
 * @param       SecurityUse -
 *
 * @return      none
 */
void ZDO_ProcessMgmtLqiReq( byte TransSeq, zAddrType_t *SrcAddr, byte StartIndex, byte SecurityUse )
{
  byte x;
  byte index;
  byte numItems;
  byte maxItems;
  ZDP_MgmtLqiItem_t* table;
  ZDP_MgmtLqiItem_t* item;
  neighborEntry_t    entry;
  byte aItems;
  associated_devices_t *aDevice;

  // Get the number of neighbor items
  NLME_GetRequest( nwkNumNeighborTableEntries, 0, &maxItems );

  // Get the number of associated items
  aItems = (uint8)AssocCount( PARENT, CHILD_FFD_RX_IDLE );
  // Total number of items
  maxItems += aItems;

  // Start with the supplied index
  numItems = maxItems - StartIndex;

  // limit the size of the list
  if ( numItems > ZDO_MAX_LQI_ITEMS )
    numItems = ZDO_MAX_LQI_ITEMS;

  // Allocate the memory to build the table
  table = (ZDP_MgmtLqiItem_t*)osal_mem_alloc( (short)
            ( numItems * sizeof( ZDP_MgmtLqiItem_t ) ) );

  if ( table != NULL )
  {
    x = 0;
    item = table;
    index = StartIndex;

    // Loop through associated items and build list
    for ( ; x < numItems; x++ )
    {
      if ( index < aItems )
      {
        // get next associated device
        aDevice = AssocFindDevice( index++ );

        // set basic fields
        item->panID   = _NIB.nwkPanId;
        osal_cpyExtAddr( item->extPanID, _NIB.extendedPANID );
        item->nwkAddr = aDevice->shortAddr;
        item->permit  = ZDP_MGMT_BOOL_UNKNOWN;
        item->depth   = 0xFF;
        item->lqi     = aDevice->linkInfo.rxCost;

        osal_memset( item->extAddr, 0x00, Z_EXTADDR_LEN );

        // use association info to set other fields
        if ( aDevice->nodeRelation == PARENT )
        {
          if (  aDevice->shortAddr == 0 )
          {
            item->devType = ZDP_MGMT_DT_COORD;
          }
          else
          {
            item->devType = ZDP_MGMT_DT_ROUTER;
          }

          item->rxOnIdle = ZDP_MGMT_BOOL_UNKNOWN;
          item->relation = ZDP_MGMT_REL_PARENT;
        }
        else
        {
          if ( aDevice->nodeRelation < CHILD_FFD )
          {
            item->devType = ZDP_MGMT_DT_ENDDEV;

            if ( aDevice->nodeRelation == CHILD_RFD )
            {
              item->rxOnIdle = FALSE;
            }
            else
            {
              item->rxOnIdle = TRUE;
            }
          }
          else
          {
            item->devType = ZDP_MGMT_DT_ROUTER;

            if ( aDevice->nodeRelation == CHILD_FFD )
            {
              item->rxOnIdle = FALSE;
            }
            else
            {
              item->rxOnIdle = TRUE;
            }
          }

          item->relation = ZDP_MGMT_REL_CHILD;
        }

        item++;
      }
      else
      {
        if ( StartIndex <= aItems )
          // Start with 1st neighbor
          index = 0;
        else
          // Start with >1st neighbor
          index = StartIndex - aItems;
        break;
      }
    }

    // Loop through neighbor items and finish list
    for ( ; x < numItems; x++ )
    {
      // Add next neighbor table item
      NLME_GetRequest( nwkNeighborTable, index++, &entry );

      // set ZDP_MgmtLqiItem_t fields
      item->panID    = entry.panId;
      osal_memset( item->extPanID, 0x00, Z_EXTADDR_LEN);
      osal_memset( item->extAddr, 0x00, Z_EXTADDR_LEN );
      item->nwkAddr  = entry.neighborAddress;
      item->rxOnIdle = ZDP_MGMT_BOOL_UNKNOWN;
      item->relation = ZDP_MGMT_REL_UNKNOWN;
      item->permit   = ZDP_MGMT_BOOL_UNKNOWN;
      item->depth    = 0xFF;
      item->lqi      = entry.linkInfo.rxCost;

      if ( item->nwkAddr == 0 )
      {
        item->devType = ZDP_MGMT_DT_COORD;
      }
      else
      {
        item->devType = ZDP_MGMT_DT_ROUTER;
      }

      item++;
    }

    // Send response
    ZDP_MgmtLqiRsp( TransSeq, SrcAddr, ZSuccess, maxItems,
                    StartIndex, numItems, table, false );

    osal_mem_free( table );
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -