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

📄 porttopcaps.c

📁 ucos在NEC平台下的移植
💻 C
字号:

#include "aps_headers.h"
#include "mac_headers.h"
#include "swsZigbeeNWK_headers.h"

volatile  LRWPAN_STATUS_ENUM aplStatus;
extern NLDE_DATA_REQUEST_INFO nldeDataRequestInfo;
extern NWK_FORMATION_INFO nwkFormInfo;
extern NWK_JOIN_INFO     nwkJoinInfo;
extern UINT16                  deviceShortAddress;
extern UINT16 ping_cnt;
extern BYTE rxFlag;              //set from within usrRxPacketCallback
extern UINT16 numTimeouts;
extern NWK_NETWORK_DISCOVERY_INFO nwkNetworkDiscoveryInfo;
extern ADDRESS dstADDR;
volatile APS_STATE_ENUM apsState;

APS_RX_DATA a_aps_rx_data;
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//  void apsdeDataRequest(UINT8 dstAddrMode,ADDRESS *dstAddress,UINT8 dstEndpoint,UINT16 profiled,UINT8 clusterID,UINT8 srcEndpoint,UINT8 asduLength,BYTE *asdu,BYTE txOptions,UINT8 discoverRoute,UINT8 radiusCounter);
//
//  DESCRIPTION:
//      The aps layer use this function to transmit a data packet.
//
//  PARAMETERS:
//          ........
//     
//  NOTE:this function will be used in ping_pong_modify.c .
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
void apsdeDataRequest(UINT8 dstAddrMode,ADDRESS *dstAddress,UINT8 dstEndpoint,UINT16 profiled,UINT8 clusterID,UINT8 srcEndpoint,UINT8 asduLength,BYTE *asdu,BYTE txOptions,UINT8 discoverRoute,UINT8 radiusCounter)
{
 nldeDataRequestInfo.broadcastRadius=radiusCounter;
 nldeDataRequestInfo.pDestAddr=dstAddress;
 nldeDataRequestInfo.nsduLength=asduLength+APS_HEADER_LENGTH;
 nldeDataRequestInfo.securityEnable=FALSE;
 nldeDataRequestInfo.nsduHandle=randNumGenerator(255);
 ByteArrayContentCopy(nldeDataRequestInfo.pNsdu, asdu, asduLength);
 nldeDataRequestInfo.discoverRoute=SUPPRESS_ROUTE_DISCOVERY; //0x00

 aplStatus=LRWPAN_STATUS_APS_INPROGRESS;
  nldeDataRequest( nldeDataRequestInfo.pDestAddr, nldeDataRequestInfo.nsduLength, nldeDataRequestInfo.pNsdu, nldeDataRequestInfo.nsduHandle, nldeDataRequestInfo.broadcastRadius, nldeDataRequestInfo.discoverRoute, nldeDataRequestInfo.securityEnable);
 conPrintROMString("Finish apsdeDataRequest() ! ");
 conPCRLF();
 aplStatus=LRWPAN_STATUS_SUCCESS;
}




//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//  void aplFormNetwork();
//
//  DESCRIPTION:
//         The aps layer use this function to form a network and wait other devices to join!
//  PARAMETER:
//         There should be some parameters,but I am in portting and testing so the parameters are ignored.
//  RETURN-VALUE:
//         NONE.
//-------------------------------------------------------------------------------------------------------------------------------------------------
#if defined(LRWPAN_COORDINATOR)||defined(NWK_OPT_ZIGBEE_PAN_COORDINATOR)
void aplFormNetwork()
{

 nwkFormInfo.scanChannels=LRWPAN_DEFAULT_CHANNEL_MASK;
 nwkFormInfo.scanDuration=LRWPAN_DEFAULT_CHANNEL_SCAN_DURATION;
 nwkFormInfo.batteryLifeExtension=FALSE;
 nwkFormInfo.beaconOrder=15;
 nwkFormInfo.panID=LRWPAN_DEFAULT_PANID;
 nwkFormInfo.superframeOrder=15;

 aplStatus=LRWPAN_STATUS_APS_INPROGRESS;
 aplStatus=(LRWPAN_STATUS_ENUM)nlmeNetworkFormationRequest(nwkFormInfo.scanChannels, nwkFormInfo.scanDuration, nwkFormInfo.beaconOrder, nwkFormInfo.superframeOrder, nwkFormInfo.panID, nwkFormInfo.batteryLifeExtension);
 conPrintROMString("Finish aplFormNetwork() ! ");
 conPCRLF();
 
}
#endif


//------------------------------------------------------------------------------------------------
// void  aplJoinNetwork();
// 
//  DESCRIPTION:
//        The aps layer use this function to join a formed network.
//  PARAMETER:
//         There should be some parameters,but I am in portting and testing so the parameters are ignored.
//  RETURN-VALUE:
//         NONE.
//-----------------------------------------------------------------------------------------------------------
void  aplJoinNetwork()
{
 //要执行加入网络的操作,设备需要首先执行发现网络的操作,只有执行发现网络的操作之后
 //设备的邻居表中才存放了信息,这些信息就是设备在加入网络的过程中要使用的信息
 nwkJoinInfo.panID=LRWPAN_DEFAULT_PANID;
 nwkJoinInfo.joinAsRouter=FALSE;
 nwkJoinInfo.rejoinNetwork=FALSE;
 nwkJoinInfo.scanChannels=LRWPAN_DEFAULT_CHANNEL_MASK;
 nwkJoinInfo.scanDuration=LRWPAN_DEFAULT_CHANNEL_SCAN_DURATION;
 nwkJoinInfo.powerSource=0;
 nwkJoinInfo.macSecurity=FALSE;
 nwkJoinInfo.rxOnWhenIdle=1;
 
 nwkNetworkDiscoveryInfo.scanChannels=LRWPAN_DEFAULT_CHANNEL_MASK;
 nwkNetworkDiscoveryInfo.scanDuration=LRWPAN_DEFAULT_CHANNEL_SCAN_DURATION;
 

 aplStatus=LRWPAN_STATUS_APS_INPROGRESS;

 nlmeNetworkDiscoveryRequest(nwkNetworkDiscoveryInfo.scanChannels,nwkNetworkDiscoveryInfo.scanDuration,&nwkNetworkDiscoveryInfo.nwkDiscoveryResult);
 
 nlmeJoinRequest(nwkJoinInfo.panID, nwkJoinInfo.joinAsRouter, nwkJoinInfo.rejoinNetwork, nwkJoinInfo.scanChannels, nwkJoinInfo.scanDuration, nwkJoinInfo.powerSource, nwkJoinInfo.rxOnWhenIdle, nwkJoinInfo.macSecurity);
 conPrintROMString("Finish nlmeNetworkDiscoveryRequest() and nlmeJoinRequest() ! \n");
 conPCRLF();
 
 
 //when the APS layer finish the operation ,the APS layer will change the apsState;
 apsState = APS_STATE_IDLE;

}

//------------------------------------------------------------------------------------------------
// void  aplRejoinNetwork();
// 
//  DESCRIPTION:
//        The aps layer use this function to join a formed network.
//  PARAMETER:
//         There should be some parameters,but I am in portting and testing so the parameters are ignored.
//  RETURN-VALUE:
//         NONE.
//-----------------------------------------------------------------------------------------------------------
void  aplRejoinNetwork()
{
 nwkJoinInfo.panID=LRWPAN_DEFAULT_PANID;
 nwkJoinInfo.joinAsRouter=FALSE;
 nwkJoinInfo.rejoinNetwork=TRUE;
 nwkJoinInfo.scanChannels=LRWPAN_DEFAULT_CHANNEL_MASK;
 nwkJoinInfo.scanDuration=LRWPAN_DEFAULT_CHANNEL_SCAN_DURATION;
 nwkJoinInfo.powerSource=0;
 nwkJoinInfo.macSecurity=FALSE;
 nwkJoinInfo.rxOnWhenIdle=1;
 
 aplStatus=LRWPAN_STATUS_APS_INPROGRESS;
 nlmeJoinRequest(nwkJoinInfo.panID, nwkJoinInfo.joinAsRouter, nwkJoinInfo.rejoinNetwork, nwkJoinInfo.scanChannels, nwkJoinInfo.scanDuration, nwkJoinInfo.powerSource, nwkJoinInfo.rxOnWhenIdle, nwkJoinInfo.macSecurity);
 conPrintROMString("Finish nlmeRejoinRequest() ! ");
 conPCRLF();
 aplStatus=LRWPAN_STATUS_SUCCESS;
}

//---------------------------------------------------------------------------------------------------
//  LRWPAN_STATUS_ENUM  aplGetStatus();
//
//   DESCRIPTION:
//         The aps layer use this function to return the status of aps layer.
//   PARAMETER:
//         This function doesn't need any parameter.
//   RETURN-VALUE:
//         LRWPAN_STATUS_ENUM:aplStatus.--indicates if the operation is successful.
//         The apsStatus should be a global variable.
//------------------------------------------------------------------------------------------------
LRWPAN_STATUS_ENUM  aplGetStatus()
{
  return  aplStatus;
}


//----------------------------------------------------------------------------------------------------
//  LRWPAN_STATUS_ENUM  usrRxPacketCallback(void) ;
//
//  DESCRIPTION:
//      This should be the apsdeDataIndication();called by network,but implemented by APS.
//  PARAMETER:
//       NONE.--It is temp,there should be some parameters.
//   RETURN-VALUE:
//       LRWPAN_STATUS_ENUM--indicates if the operation is successful.
//  NOTE:
//       callback from NWK (shoule be APS) when packet is received,user must do something with data as it is freed
//------------------------------------------------------------------------------------------------
LRWPAN_STATUS_ENUM  usrRxPacketCallback(void) {

	BYTE len, *ptr;

	//just print out this data

	conPrintROMString("User Data Packet Received: \n");
	conPrintROMString("SrcSADDR: ");
	conPrintUINT16(aplGetRxSrcSADDR());
	conPrintROMString(", DstEp: ");
	conPrintUINT8(aplGetRxDstEp());
	conPrintROMString(", Cluster: ");
	conPrintUINT8(aplGetRxCluster());
	conPrintROMString(", MsgLen: ");
	len = aplGetRxMsgLen();
	conPrintUINT8(len);
	conPrintROMString(",RSSI: ");
	conPrintUINT8(aplGetRxRSSI());
	conPCRLF();
	conPrintROMString("PingCnt: ");
	ptr = aplGetRxMsgData();
	ping_cnt = *ptr;
	ptr++;
	ping_cnt += ((UINT16)*ptr)<<8;
	conPrintUINT16(ping_cnt);
	conPrintROMString(", RxTimeouts: ");
	conPrintUINT16(numTimeouts);
	rxFlag = 1;//signal that we got a packet
	//use this source address as the next destination address
	dstADDR.Short = aplGetRxSrcSADDR();   
	conPCRLF();
	return LRWPAN_STATUS_SUCCESS;
}


//---------------------------------------------------------------------------------------------------
//   UINT32 aplGetLastTxTime();
//
//   DESCRIPTION:
//           This function is used to return the tx time of last transmitted packet!
//   PARAMETER:
//           NONE;
//   RETURN-VALUE:
//           NONE;
//---------------------------------------------------------------------------------------------------
UINT32 aplGetLastTxTime()
{
 UINT32 txTime;
 conPrintROMString("Finish aplGetLastTxTime() ! ");
 conPCRLF();
 return txTime;
  
}

//-------------------------------------------------------------------------------------------------
//   ZBOOL apsBusy();
//
//   DESCRIPTION:
//           This function is used to justify if the aps layer is in operation!
//   PARAMETER:
//           NONE;
//   RETURN-VALUE:
//           ZBOOL;
//---------------------------------------------------------------------------------------------------
ZBOOL apsBusy()
{
  conPrintROMString("Finish apsBusy()!");
  conPCRLF();
  return (apsState != APS_STATE_IDLE);
}


void aplSetMacMaxFrameRetries()
{
 //mpib.macMaxAckRetries=x;
}

UINT16 aplGetParentShortAddress()
{
 return mpib.macCoordShortAddress;
}

BYTE * aplGetParentLongAddress()
{
 return mpib.macCoordExtendedAddress;
}

UINT16 aplGetMyShortAddress()
{
 return deviceShortAddress;
}

void aplInit()
{
 nwkInit();
 conPrintROMString("Finish aplInit() ! ");
 conPCRLF();
}

BOOL macRxBuffFull(void)
{
 conPrintROMString("Finish macRxBuffFull() ! ");
 conPCRLF();
 return FALSE;
}

⌨️ 快捷键说明

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