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

📄 nwk_aodvjr_route.c

📁 ucos在NEC平台下的移植
💻 C
字号:
//#pragma  section @@DATA Nwk_AODVjr at 0xF4FF 

#include "includes.h"

extern volatile UINT16  nwkSrcAddrInHeaderOfRecivedPacket;
extern MCPS_DATA_INFO   mcpsDataRequestInfo;
extern NWK_NIB nnib;
extern NLDE_DATA_REQUEST_INFO nldeDataRequestInfo;
extern MCPS_DATA_INDICATION  mcpsDataIndicationInfo;
extern UINT16 deviceShortAddress;
extern volatile UINT16  nwkDstAddrInHeaderOfRecivedPacket;
extern NWK_BACK_GROUND_STATE nwkBackgroundStatus;
#if defined(NWK_SUPPORT_ROUTING) && !defined(NWK_USE_TREE_ROUTING_ONLY)
 ROUTE_DISCOVERY_ENTRY   *routeDiscoveryTablePointer[NWK_ROUTE_DISCOVERY_TABLE_SIZE];
 BUFFERED_MESSAGE_INFO   *routingBufferedPackets[NWK_NUM_BUFFERED_FRAME_PENDING_ROUTE_DISCOVERY];
#endif

// Routing information
#if defined(NWK_SUPPORT_ROUTING) && !defined(NWK_USE_TREE_ROUTING_ONLY)
    ROUTE_TABLE_RNTRY   routingTable[NWK_ROUTE_TABLE_SIZE] ;  

   //  RAM copy of the current routing entry
    ROUTE_TABLE_RNTRY       currentRoutingEntry;

//     Pointer to the current routing entry in ROM
    ROUTE_TABLE_RNTRY   *pCurrentRoutingEntry=NULL;
#endif


extern NEIGHBOR_TABLE_INFO     currentNeighborTableInfo;  

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

//-------------------------------------------------------------------------------------------------------
//     ZBOOL GetNextHop(const UINT16   destAddr, UINT16* nextHop, PACKET_ROUTING_STATUS*routeStatus );
//
//     DESCRIPTION:
//                 This function finds an entry in the routing table  for the given destination address.  Note that the
//                  caller must check the route status to see how to use the next hop destination.
//     PARAMETER:
//                 UINT16 * destAddr, 
//                          Desired short address.
//                 UINT16 *nextHop,
//                          A 'value-result' parameter,points to next hop address in the route path to the desired short address.
//                 PACKET_ROUTING_STATUS *routeStatus
//                          A 'value-result' parameter,points to route status.
//     RETURN-VALUE:
//                 TRUE : an entry found in the routing table.' currentRoutingEntry' and 'pCurrentRoutingEntry'
//                            will be set the the Routing Table entry that matches the request.
//                 FALSE: no entry found.
//-------------------------------------------------------------------------------------------------------
//#if defined(NWK_SUPPORT_ROUTING) && !defined(NWK_USE_TREE_ROUTING_ONLY)
#ifndef NWK_OPT_RFD
ZBOOL GetNextHop(const UINT16   destAddr, UINT16* nextHop, PACKET_ROUTING_STATUS*routeStatus )
{
    ZBOOL                foundNextHop;
    BYTE                i;
    foundNextHop = FALSE;
    pCurrentRoutingEntry = routingTable;
    i = 0;
    do
    {
        //ReadRoutingEntryIntoRAM( &currentRoutingEntry, pCurrentRoutingEntry );
		currentRoutingEntry=*pCurrentRoutingEntry;
        if (currentRoutingEntry.destinationAddress==destAddr)
        {
            foundNextHop = TRUE;
			break;
        }
        else
        {
            i++;
            pCurrentRoutingEntry++;
        }
    } while ((i<NWK_ROUTE_TABLE_SIZE) && !foundNextHop );

   if (foundNextHop)
    {
        *nextHop = currentRoutingEntry.nextHopAddress;
        *routeStatus = currentRoutingEntry.routeStatus;
    }
    else
    {
        *routeStatus = ROUTE_INACTIVE;
    }

    return foundNextHop;
   
}
#endif

//-----------------------------------------------------------------------------------------------------------
//    ZBOOL CreateRoutingTableEntries(UINT16 destinationAddress, BYTE *routeDiscoveryIndex, BYTE *routeTableIndex );
//
//    DESCRIPTION:
//             This function creates Route Discovery Table and Routing Table entries.
//    PARAMETER:
//             UINT16  destinationAddress,
//                      The destination address.
//             BYTE *routeDiscoveryIndex,
//                      A 'value-result' parameter-Route Discovery Table index of new entry.
//             BYTE *routeTableIndex,
//                      A 'value-result' parameter-Routing Table index of new entry.
//    RETURN-VALUE:
//            TRUE:This function successfully creates the Route Discovery Table and Routing Table entries.
//            FALSE:Failed in creating Route Discovery Table  or Routing Table Entries
//    NOTE:HasRoutingCapacity() must return TRUE.
//------------------------------------------------------------------------------------------------------
#if defined(NWK_SUPPORT_ROUTING) && !defined(NWK_USE_TREE_ROUTING_ONLY)
ZBOOL CreateRoutingTableEntries( UINT16  destinationAddress, BYTE *routeDiscoveryIndex, BYTE *routeTableIndex )
{
	// See if an entry already exists for the target address  in the routing table.  Otherwise, find a free location in the
	// Routing Table.  We know one or the other is possible since HasRoutingCapacity returns TRUE.  We need to see if the destination
	// address is already in the table in case the route is being re-discovered.  Since we have a local variable, use it instead
	// of the pointer.
	BYTE index=0;
	pCurrentRoutingEntry = routingTable;
	//ReadRoutingEntryIntoRAM(& currentRoutingEntry, pCurrentRoutingEntry);
	currentRoutingEntry=*pCurrentRoutingEntry;
    while ((index <NWK_ROUTE_TABLE_SIZE) &&(currentRoutingEntry.destinationAddress!=destinationAddress))
    {
        index++;
        pCurrentRoutingEntry++;
		// ReadRoutingEntryIntoRAM( &currentRoutingEntry, pCurrentRoutingEntry );
        currentRoutingEntry=*pCurrentRoutingEntry;
    }
	if (index == NWK_ROUTE_TABLE_SIZE)
    {
		printf("\n殠貞幍歨墠泿螇幑婁殠貧嫑幎嫀

⌨️ 快捷键说明

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