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

📄 nwk_cluster_tree_route.c

📁 ucos在NEC平台下的移植
💻 C
字号:
//#pragma  section @@DATA Nwk_cluster_tree_route at 0xFB00
#include"includes.h"

extern  volatile UINT16 deviceCoordShortAddress;
extern  NWK_NIB nnib;
extern NEIGHBOR_RECORD neighborTable[NEIGHBOR_TABLE_ENTRIES]; 
extern  UINT16 deviceShortAddress;

extern NEIGHBOR_TABLE_INFO     currentNeighborTableInfo;  

extern NEIGHBOR_RECORD        *pCurrentNeighborRecord;
extern NEIGHBOR_RECORD         currentNeighborRecord;                      // Node information.

//------------------------------------------------------------------------------------------
//    int GetCskipVal(UINT8 depth);
// 
//    DESCRIPTION:
//           Return the cSkip value (the device's address size) based on the 'depth'.
//    PARAMETER:
//           UINT8 depth,
//             The device's depth in the tree.
//    RETURN-VALUE:
//           The cSkip value.
//------------------------------------------------------------------------------------------
 int GetCskipVal(UINT8 depth) {
	switch(depth){
		case 1: return(NWK_CSKIP_0);
		case 2: return(NWK_CSKIP_1);
		case 3: return(NWK_CSKIP_2);
		case 4: return(NWK_CSKIP_3);
		case 5: return(NWK_CSKIP_4);
		default:return 0;
	            }
}

//-----------------------------------------------------------------------------------------
//    void ntInitAddressAssignment(void);	
//
//    DESCRIPTION:
//             Initialize the address information.
//    PARAMETER:
//             NO.
//    RETURN-VALUE:
//             NO.
//------------------------------------------------------------------------------------------
#ifdef NWK_OPT_FFD
 void ntInitAddressAssignment(void){
    //also initialize ADDRESS assignment
   

	nnib.ChildRFDs = 0;
//	nnib.ChildRouters = 0;
	//nnib.nextChildRFD =deviceShortAddress + 1+ GetCskipVal(depth+1)*(LRWPAN_MAX_ROUTERS_PER_PARENT);
//	nnib.nextChildRouter = deviceShortAddress + 1;
}
#endif

//------------------------------------------------------------------------------------------
//    PACKET_ROUTING_STATUS UseTreeRouting(SHORT_ADDR nwkAddress, SHORT_ADDR macAddress );
//    
//    DESCRIPTION:
//                 In the program,RN+ node can do AODVjr routing and cluster-tree routing.
//                 when there is  no routing capacity,the RN+node may choose to do cluster-tree routing.
//                 This function wraps the concret operation of the cluster-tree routing.
//    PARAMETER:
//                 SHORT_ADDR nwkAddress,
//                        Desired destination network address.
//                 SHORT_ADDR *macAddress,
//                        A 'value-result' parameter,used to take back the network address of the next hop.
//   RETURN-VALUE:
//                 The routing status.
//--------------------------------------------------------------------------------------------
#ifdef NWK_SUPPORT_ROUTING
PACKET_ROUTING_STATUS UseTreeRouting(UINT16 nwkAddress, UINT16* macAddress )
{
     if (!RouteAlongTree( nwkAddress, macAddress ))
            {
                // We cannot route the message.
                return ROUTE_FAILURE_TREE_LINK;
            }
            else
            {
                // We can send the message.
                return ROUTE_SEND_TO_MAC_ADDRESS;
            }

}
#endif

//---------------------------------------------------------------------------------
//     ZBOOL IsDescendant( UINT16 parentAddr, UINT16 childAddr, BYTE parentDepth );
//
//     DESCRIPTION:
//                  This function determines if the child device is a descendant of the parent device.  
//     PARAMETER:
//                  UINT16 parentAddr, 
//                             Short address of the parent device.
//                  UINT16 childAddr,
//                              Short address of the child device
//                  BYTE parentDepth
//                              Depth of the parent
//     RETURN-VALUE:
//                  TRUE:the child of the address'childAddr'is a descendant of the parent.
//     NOTE:   If I am the coordinator, the device is always my descendant.  
//                 Otherwise, the device is my descendant if its address is within the address 
//                 range that I can allocate.
//--------------------------------------------------------------------------------                   
#ifdef NWK_SUPPORT_ROUTING
ZBOOL IsDescendant( UINT16 parentAddr, UINT16 childAddr, BYTE parentDepth )
{
   //the PAN Coordinator's depth is 0;
   if (parentDepth == 0)  
    {
        return TRUE;
    }
    else
    {
        if ((parentAddr < childAddr) &&
            (childAddr < (parentAddr + GetCskipVal( parentDepth-1 ))))
            return TRUE;
        else
            return FALSE;
    }
 
}
#endif

//------------------------------------------------------------------------
//    ZBOOL RouteAlongTree( UINT16 destTarget, UINT16 *destNextHop );
//
//    DESCRIPTION:
//                 This function determines the address of the next node to send a routing message to based on
//                  tree hierarchy. 
//    PARAMETER:
//                 UINT16 destTarget,
//                 UINT16 *destNextHop,
//                        A 'value-result' parameter,when the function completes,the  address of the next hop 
//                        will be pointed by destNextHop.
//    RETURN-VALUE:
//                 TRUE:  find out the valid next hop.
//                 FALSE: don't find out the valid next hop.
//    NOTE:    If the packet is going to one of our descendants, pass
//                  it to the next level parent.  Otherwise, pass it to our parent.
//------------------------------------------------------------------------                 
#ifdef NWK_SUPPORT_ROUTING
ZBOOL RouteAlongTree( UINT16 destTarget, UINT16 *destNextHop )
{
  ZBOOL              foundNextHop;
  BYTE               i;

  #ifdef NWK_WORK_AS_END_DEVICE
        // If the device is  an FFD end device, the device has no children, so send the message to the device's parent.
         *destNextHop = deviceCoordShortAddress;
          return TRUE;
  #else
       foundNextHop=FALSE;
       //The device is an FFD,and it doesn't work as end device,so it may have children and parent.
       //Then we should justify if the 'destTarget' is its child device or the 'destTarget' 's parent is
       // its child device,if so,the child device is the next hop.

  printf("\n檸◤JRREP妿

⌨️ 快捷键说明

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