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

📄 nwk_support.c

📁 ucos在NEC平台下的移植
💻 C
字号:
#include<swsZigbeeNWK_headers.h>
/*
 *******************************************************************************************************
 * CONFIDENTIAL                                                                                        *
 * The use of this file is restricted by SkywiseSystems                    *
 *                                                                                                     *
 * Copyright liquanling 02/09/2006                                                                          *
 *******************************************************************************************************
 * This module contains support/utility functions for the NWK sublayer. . 
 *******************************************************************************************************
 * Compiler: NEC-CC78K0                                                                                  *
 * Target platform:                                                   *
 *******************************************************************************************************
 * The revision history is located at the bottom of this file                                          *
 *********************************************************************************/

 extern NWK_NIB nnib;
//-------------------------------------------------------------------------------------------------------
//  nsupPrepareHeader(NWK_TX_PACKET *nPacket, BYTE type, BYTE addrModes, WORD srcPanId, ADDRESS ...)
//
//  DESCRIPTION:
//      Packet header assembly function, used for data and command frames.
//      The NWK header includes:frame control field,destination address field,
//                                            source assress field,radius field,
//                                            sequence number field.
//
//  PARAMETERS:
//      NWK_TX_PACKET *nPacket
//          The packet structure to update (this function affects the header part) 
//      BYTE type
//          FRAME_TYPE_NWK_DATA or FRAME_TYPE_NWK_COMMAND
//      BYTE addrModes
//          Address mode for source and destination
//          (SRC_ADDR_SHORT, SRC_ADDR_EXT or 0) | (DEST_ADDR_SHORT, DEST_ADDR_EXT or 0)
//      ADDRESS *pSrcAddr
//          Pointer to the source address (short or extended)
//      ADDRESS *pDestAddr, 
//          Pointer to the destination address (short or extended)
//-----------------------------------------------------------------------------------------------------
void nsupPrepareHeader(NWK_TX_PACKET *nPacket,ADDRESS *pDestAddr)
{
 BYTE frameControl;
 //use frameControl variable to record the information of the frame control
 UINT8 length = 0;
 ///BYTE macShortAddress[2];
 UINT16  macShortAddress;
 MAC_ENUM result;
 result=mlmeGetRequest(MAC_SHORT_ADDRESS, &macShortAddress);

 //the type of the frame

 //nPacket->type=type;
 //the frame control field
 frameControl=( nPacket->type)&FRAME_TYPE_BM;
 frameControl|=PROTOCOL_VERSION_BM;
 frameControl|=(nPacket->discoverRoute)&DISCOVER_ROUTE_BM;
 //the above do the initialization of the first byte of the frame control field.
 nPacket->nHeader[length++]=frameControl;
 #if NWK_OPT_SECURITY
       nPacket->nHeader[length++]=SECURITY_BM;
  #else
       nPacket->nHeader[length++]=0;
  #endif
 //the second byte of the frame control field is only 'Security'.
 //the following will construct the 'Routing fields' of the NWK header.
 /// ContentCopy(nPacket->nHeader+length, pDestAddr->Short, 2);
  nPacket->nHeader[length++]=(BYTE)((pDestAddr->Short)&0xff);
  nPacket->nHeader[length++]= (BYTE)((pDestAddr->Short)>>8);
  /// length=length+2;
   //fetch the device's short address and put the source address in the NWK header
  ///ContentCopy(nPacket->nHeader+length,macShortAddress, 2);
  nPacket->nHeader[length++]=(BYTE)(macShortAddress&0xff);
   nPacket->nHeader[length++]=(BYTE)(macShortAddress>>8);
   //memcpy(nPacket->nHeader + length, (BYTE*)&mac_addr_tbl[0].saddr, 2);
   
   nPacket->nHeader[length++]=nPacket->radius;
   nPacket->nHeader[length++]=nnib.nwkSequcenceNumber++;
   // the end of the construction of the frame control field;
   nPacket->headerLength=length; 
 }

⌨️ 快捷键说明

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