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

📄 zdapp.c

📁 Zigbee2006入门源代码,包括了Zigbee的入门介绍,和源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
  HalLcdWriteScreen( "End Device Bind", "Rcvd" );
#endif
}
#endif // ZDO_COORDINATOR

#if !defined ( REFLECTOR ) && defined ( ZDO_BIND_UNBIND_RESPONSE )
/*********************************************************************
 * @fn      ZDApp_AppBindReq()
 *
 * @brief
 *
 *   Called to send an App Bind Request message.
 *
 * @param  SrcAddr     - Source address ( who sent the message )
 * @param  SrcAddress  - Source Address (64 bit)
 * @param  SrcEndPoint - Source endpoint
 * @param  ClusterID   - Cluster ID
 * @param  DstAddress  - Destination Address (64 bit)
 * @param  DstEndPoint - Destination endpoint
 * @param  SecurityUse - Security enable/disable
 *
 * @return  none
 */
void ZDApp_AppBindReq( byte TransSeq, zAddrType_t *SrcAddr, byte *SrcAddress,
                      byte SrcEndPoint, cId_t ClusterID, byte *DstAddress,
                      byte DstEndPoint, byte SecurityUse, uint8 Type )
{
  ZDO_BindReq_t *pBindReq;

  if ( ZDApp_BindReq_TaskID )
  {
    // Send the IEEE Address response structure to the registered task
    pBindReq = (ZDO_BindReq_t *)osal_msg_allocate( sizeof( ZDO_BindReq_t ) );
    if ( pBindReq )
    {
      pBindReq->event_hdr.event = Type;

      // Build the structure
      pBindReq->hdr.srcAddr = SrcAddr->addr.shortAddr;
      pBindReq->hdr.transSeq = TransSeq;
      pBindReq->hdr.SecurityUse = SecurityUse;

      osal_cpyExtAddr( pBindReq->srcAddr, SrcAddress );
      pBindReq->srcEP = SrcEndPoint;
      pBindReq->clusterID = ClusterID;
      osal_cpyExtAddr( pBindReq->dstAddr, DstAddress );
      pBindReq->dstEP = DstEndPoint;

      osal_msg_send( ZDApp_BindReq_TaskID, (uint8 *)pBindReq );
    }
  }
}
#endif // !REFLECTOR && ZDO_BIND_UNBIND_RESPONSE

#if defined ( REFLECTOR ) || defined ( ZDO_BIND_UNBIND_RESPONSE )
/*********************************************************************
 * @fn      ZDApp_BindReqCB()
 *
 * @brief
 *
 *   Called by ZDO when a Bind Request message is received.
 *
 * @param  SrcAddr     - Source address ( who sent the message )
 * @param  SrcAddress  - Source Address (64 bit)
 * @param  SrcEndPoint - Source endpoint
 * @param  ClusterID   - Cluster ID
 * @param  DstAddress  - Destination Address (64 bit)
 * @param  DstEndPoint - Destination endpoint
 * @param  SecurityUse - Security enable/disable
 *
 * @return  none
 */
void ZDApp_BindReqCB( byte TransSeq, zAddrType_t *SrcAddr, byte *SrcAddress,
                      byte SrcEndPoint, cId_t ClusterID, zAddrType_t *DstAddress,
                      byte DstEndPoint, byte SecurityUse )
{
#if defined ( REFLECTOR )
  zAddrType_t SourceAddr;       // Binding Source addres
  byte bindStat;

  SourceAddr.addrMode = Addr64Bit;
  osal_cpyExtAddr( SourceAddr.addr.extAddr, SrcAddress );

  if ( DstAddress->addrMode != Addr64Bit &&
         DstAddress->addrMode != AddrGroup )
  {
    bindStat = ZDP_NOT_SUPPORTED;
  }

  else
  { // Check source endpoints
    if ( SrcEndPoint == 0 || SrcEndPoint > MAX_ENDPOINTS )
    {
      bindStat = ZDP_INVALID_EP;
    }
    // Check the destination endpoints for ext address mode
    else if ( ( DstAddress->addrMode == Addr64Bit ) &&
            ( DstEndPoint == 0 || DstEndPoint > MAX_ENDPOINTS ) )
    {
      bindStat = ZDP_INVALID_EP;
    }

    else
    {
#if defined ( ZDO_NWKADDR_REQUEST )
      {
        uint16 nwkAddr;

        // Check for the source address
        if ( APSME_LookupNwkAddr( SrcAddress, &nwkAddr ) == FALSE )
        {
          ZDP_NwkAddrReq( SrcAddress, ZDP_ADDR_REQTYPE_SINGLE, 0, 0 );
        }

        // Check for the destination address
        if ( DstAddress->addrMode == Addr64Bit )
        {
          if ( APSME_LookupNwkAddr( DstAddress->addr.extAddr, &nwkAddr ) == FALSE )
          {
            ZDP_NwkAddrReq( DstAddress->addr.extAddr, ZDP_ADDR_REQTYPE_SINGLE, 0, 0 );
          }
        }
      }
#endif

      if ( APSME_BindRequest( &SourceAddr, SrcEndPoint, ClusterID,
                     DstAddress, DstEndPoint ) == ZSuccess )
      {
        bindStat = ZDP_SUCCESS;
        // Notify to save info into NV
        osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, 250 );
      }
      else
        bindStat = ZDP_TABLE_FULL;
    }
  }
  // Send back a response message
  ZDP_BindRsp( TransSeq, SrcAddr, bindStat, SecurityUse );

#else  // must be ZDO_BIND_UNBIND_RESPONSE

  ZDApp_AppBindReq( TransSeq, SrcAddr, SrcAddress, SrcEndPoint, ClusterID,
                    DstAddress->addr.extAddr, DstEndPoint, SecurityUse, ZDO_BIND_REQUEST );

#endif // REFLECTOR
}
#endif // REFLECTOR OR ZDO_BIND_UNBIND_RESPONSE

#if defined ( REFLECTOR ) || defined ( ZDO_BIND_UNBIND_RESPONSE )
/*********************************************************************
 * @fn      ZDApp_UnbindReqCB()
 *
 * @brief
 *
 *   Called by ZDO when an Unbind Request message is received.
 *
 * @param  SrcAddr  - Source address
 * @param  SrcAddress - Source Address (64 bit)
 * @param  SrcEndPoint - Source endpoint
 * @param  ClusterID - Cluster ID
 * @param  DstAddress - Destination Address (64 bit)
 * @param  DstEndPoint - Destination endpoint
 * @param  SecurityUse - Security enable/disable
 *
 * @return  none
 */
void ZDApp_UnbindReqCB( byte TransSeq, zAddrType_t *SrcAddr, byte *SrcAddress,
                        byte SrcEndPoint, cId_t ClusterID, zAddrType_t *DstAddress,
                        byte DstEndPoint, byte SecurityUse )
{
#if defined ( REFLECTOR )
  zAddrType_t SourceAddr;       // Binding Source addres
  byte bindStat;

  SourceAddr.addrMode = Addr64Bit;
  osal_cpyExtAddr( SourceAddr.addr.extAddr, SrcAddress );

  // Check endpoints
  if ( SrcEndPoint == 0 || SrcEndPoint > MAX_ENDPOINTS ||
       DstEndPoint == 0 || DstEndPoint > MAX_ENDPOINTS )
  {
    bindStat = ZDP_INVALID_EP;
  }

  else
  {
    if ( APSME_UnBindRequest( &SourceAddr, SrcEndPoint, ClusterID,
                             DstAddress, DstEndPoint ) == ZSuccess )
    {
      bindStat = ZDP_SUCCESS;

      // Notify to save info into NV
      osal_start_timerEx( ZDAppTaskID, ZDO_NWK_UPDATE_NV, 250 );
    }
    else
      bindStat = ZDP_NO_ENTRY;
  }

  // Send back a response message
  ZDP_UnbindRsp( TransSeq, SrcAddr, bindStat, SecurityUse );

#else // Must be ZDO_BIND_UNBIND_RESPONSE

  ZDApp_AppBindReq( TransSeq, SrcAddr, SrcAddress, SrcEndPoint, ClusterID,
                    DstAddress->addr.extAddr, DstEndPoint, SecurityUse, ZDO_UNBIND_REQUEST );

#endif // ZDO_BIND_UNBIND_RESPONSE
}
#endif // REFLECTOR OR ZDO_BIND_UNBIND_RESPONSE

/*********************************************************************
 * @fn      ZDApp_SendNewDstAddr()
 *
 * @brief
 *
 *   Used to send an OSAL message to an application that contains a
 *   new destination address
 *
 * @param  dstEP  - Destination endpoint
 * @param  dstAddr - response status
 * @param  clusterID - relavent cluster for this dst address
 * @param  removeFlag - false if add, true to remove
 * @param  task_id - What task to send it to
 * @param  endpoint - who the new address is for
 *
 * @return  none
 */
void ZDApp_SendNewDstAddr( byte dstEP, zAddrType_t *dstAddr,
                   cId_t clusterID, byte removeFlag, byte task_id, byte endpoint )
{
  byte bufLen;
  ZDO_NewDstAddr_t *msgPtr;

  // Send the address to the task
  bufLen = sizeof(ZDO_NewDstAddr_t);

  msgPtr = (ZDO_NewDstAddr_t *)osal_msg_allocate( bufLen );
  if ( msgPtr )
  {
    msgPtr->hdr.event = ZDO_NEW_DSTADDR;
    msgPtr->dstAddrDstEP = dstEP;
    osal_memcpy(&msgPtr->dstAddr, dstAddr, sizeof( zAddrType_t ) );
    msgPtr->dstAddrClusterIDLSB = LO_UINT16( clusterID );
    msgPtr->dstAddrClusterIDMSB = HI_UINT16( clusterID );
    msgPtr->dstAddrRemove = removeFlag;
    msgPtr->dstAddrEP = endpoint;

    osal_msg_send( task_id, (uint8 *)msgPtr );
  }
}

/*********************************************************************
 * @fn      ZDApp_SendEventMsg()
 *
 * @brief
 *
 *   Sends a Network Join message
 *
 * @param  cmd - command ID
 * @param  len - length (in bytes) of the buf field
 * @param  buf - buffer for the rest of the message.
 *
 * @return  none
 */
void ZDApp_SendEventMsg( byte cmd, byte len, byte *buf )
{
  ZDApp_SendMsg( ZDAppTaskID, cmd, len, buf );
}

/*********************************************************************
 * @fn      ZDApp_SendMsg()
 *
 * @brief   Sends a OSAL message
 *
 * @param  taskID - Where to send the message
 * @param  cmd - command ID
 * @param  len - length (in bytes) of the buf field
 * @param  buf - buffer for the rest of the message.
 *
 * @return  none
 */
void ZDApp_SendMsg( byte taskID, byte cmd, byte len, byte *buf )
{
  osal_event_hdr_t *msgPtr;

  // Send the address to the task
  msgPtr = (osal_event_hdr_t *)osal_msg_allocate( len );
  if ( msgPtr )
  {
    if ( (len > 0) && (buf != NULL) )
      osal_memcpy( msgPtr, buf, len );

    msgPtr->event = cmd;
    osal_msg_send( taskID, (byte *)msgPtr );
  }
}

#if defined ( ZDO_NWKADDR_REQUEST )
/*********************************************************************
 * @fn      ZDApp_NwkAddrRspCB()
 *
 * @brief
 *
 *   Called by ZDO when a NWK_addr_rsp message is received.
 *
 * @param  SrcAddr  - Source address
 * @param  Status - response status
 * @param  IEEEAddr - 64 bit IEEE address of device
 * @param  aoi - 16 bit network address of interest.
 * @param  NumAssocDev - number of associated devices to reporting device
 * @param  AssocDevList - array short addresses of associated devices
 *
 * @return  none
 */
void ZDApp_NwkAddrRspCB( zAddrType_t *SrcAddr, byte Status, byte *IEEEAddr,
                         uint16 nwkAddr, byte NumAssocDev,
                         byte StartIndex, uint16 *AssocDevList )
{
  uint8 bufLen;
  ZDO_NwkAddrResp_t *pNwkAddrRsp;

#if defined ( MT_ZDO_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 ( _zdoCallbackSub & CB_ID_ZDO_NWK_ADDR_RSP )
  {
    zdo_MTCB_NwkIEEEAddrRspCB( SPI_CB_ZDO_NWK_ADDR_RSP, SrcAddr, Status,
                  IEEEAddr, nwkAddr, NumAssocDev, StartIndex, AssocDevList );
    return;
  }
#endif  //MT_ZDO_FUNC

  if ( ZDApp_NwkAddrRsp_TaskID )
  {
    // Send the NWK Address response structure to the registered task
    bufLen = sizeof( ZDO_NwkAddrResp_t ) + sizeof( uint16 ) * NumAssocDev;

    pNwkAddrRsp = (ZDO_NwkAddrResp_t *)osal_msg_allocate( bufLen );

    if ( pNwkAddrRsp )
    {
      pNwkAddrRsp->hdr.event = ZDO_NWK_ADDR_RESP;

      // Build the structure
      pNwkAddrRsp->nwkAddr = nwkAddr;
      osal_cpyExtAddr( pNwkAddrRsp->extAddr, IEEEAddr );
      pNwkAddrRsp->numAssocDevs = NumAssocDev;
      pNwkAddrRsp->startIndex = StartIndex;
      osal_memcpy( pNwkAddrRsp->devList, AssocDevList, (sizeof( uint16 ) * NumAssocDev) );

      osal_msg_send( ZDApp_NwkAddrRsp_TaskID, (uint8 *)pNwkAddrRsp );
    }
  }
}
#endif // ZDO_NWKADDR_REQUEST

#if defined ( ZDO_IEEEADDR_REQUEST )
/*********************************************************************
 * @fn      ZDApp_IEEEAddrRspCB()
 *
 * @brief
 *
 *   Called by ZDO when a NWK_addr_rsp message is received.
 *
 * @param  SrcAddr  - Source address
 * @param  Status - response status
 * @param  IEEEAddr - 64 bit IEEE address of device
 * @param  aoi - 16 bit network address of interest.
 * @param  NumAssocDev - number of associated devices to reporting device
 * @param  AssocDevList - array short addresses of associated devices
 *
 * @return  none
 */
void ZDApp_IEEEAddrRspCB( zAddrType_t *SrcAddr, byte Status, byte *IEEEAddr,
                          uint16 aoi, byte NumAssocDev,
                          byte StartIndex, uint16 *AssocDevList )
{
  uint8 bufLen;
  ZDO_IEEEAddrResp_t *pIEEEAddrRsp;

#if defined ( MT_ZDO_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 ( _zdoCallbackSub & CB_ID_ZDO_IEEE_ADDR_RSP )
  {
    zdo_MTCB_NwkIEEEAddrRspCB( SPI_CB_ZDO_IEEE_ADDR_RSP, SrcAddr, Status,
                  IEEEAddr, 0, NumAssocDev, StartIndex, AssocDevList );
    return;
  }
#endif  //MT_ZDO_FUNC

  if ( ZDApp_IEEEAddrRsp_TaskID )
  {
    // Send the IEEE Address response structure to the registered task
    bufLen = sizeof( ZDO_IEEEAddrResp_t ) + sizeof( uint16 ) * NumAssocDev;

    pIEEEAddrRsp = (ZDO_IEEEAddrResp_t *)osal_msg_allocate( bufLen );
    if ( pIEEEAddrRsp )
    {
      pIEEEAddrRsp->hdr.event = ZDO_IEEE_ADDR_RESP;

      // Build the structure
      pIEEEAddrRsp->nwkAddr = aoi;
      osal_cpyExtAddr( pIEEEAddrRsp->extAddr, IEEEAddr );
      pIEEEAddrRsp->numAssocDevs = NumAssocDev;
      pIEEEAddrRsp->startIndex = StartIndex;
      osal_memcpy( pIEEEAddrRsp->devList, AssocDevList, (sizeof( uint16 ) * NumAssocDev) );

      osal_msg_send( ZDApp_IEEEAddrRsp_TaskID, (uint8 *)pIEEEAddrRsp );
    }
  }
}
#endif // ZDO_IEEEADDR_REQUEST

#if defined ( ZDO_NODEDESC_REQUEST )
/*********************************************************************
 * @fn      ZDApp_NodeDescRspCB()
 *
 * @brief
 *
 *   Called by ZDO when a Node_Desc_rsp message is received.
 *
 * @param  SrcAddr  - Source address
 * @param  Status - response status
 * @param  aoi - 16 bit network address of interest.
 * @param  pNodeDesc - pointer to the devices Node Descriptor
 *                     NULL if Status != ZDP_SUCCESS
 *
 * @return  none
 */
void ZDApp_NodeDescRspCB( zAddrType_t *SrcAddr, byte Status, uint16 aoi,
                          NodeDescriptorFormat_t *pNodeDesc )
{
#if defined ( MT_ZDO_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 ( _zdoCallbackSub & CB_ID_ZDO_NODE_DESC_RSP )
  {
    zdo_MTCB_NodeDescRspCB( SrcAddr, Status, aoi, pNodeDesc );
    return;
  }
#endif  //MT_ZDO_FUNC
}
#endif

#if defined ( ZDO_POWERDESC_REQUEST )
/*********************************************************************
 * @fn     

⌨️ 快捷键说明

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