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

📄 datasendexamplem.nc

📁 Zigbee的nesc源码
💻 NC
字号:
/*
 *
 * @author IPP HURRAY http://www.hurray.isep.ipp.pt/art-wise
 * @author Andre Cunha
 *
 */
module DataSendExampleM
{
  provides {
   
   interface StdControl;
   
}
  uses {
  	interface Timer;
    interface Leds;
	
	interface MLME_START;
	
	interface MLME_ASSOCIATE;
	interface MLME_DISASSOCIATE;
	
	interface MLME_SCAN;
	interface MLME_RESET;
	
	interface MLME_SYNC;
	interface MLME_SYNC_LOSS;
	
	interface MLME_BEACON_NOTIFY;
	
	interface MLME_COMM_STATUS;
	
	interface MLME_SET;
	interface MLME_GET;
   
    interface MLME_GTS;
	
	interface MLME_POLL;
   
   //MCPS
   
	interface MCPS_DATA;
	interface MCPS_PURGE;
	
	interface StdControl as Mac_control;

	interface Time;
	
	interface Timer as Timer_send;
	
	   }
}
implementation
{

	uint8_t beacon_present=0;
	uint8_t on_sync=0;
	
	PANDescriptor pan_des;
	
	uint32_t my_short_address=0x00000000;
	uint32_t my_pan_id=0x00001234;
	
	uint32_t DestinationMote[2];
	


command result_t StdControl.init() {
    

    return SUCCESS;
}

command result_t StdControl.start() {

	printfUART("i_am_pan: %i\n", TYPE_DEVICE);
	
	DestinationMote[0]=0x00000000;
	DestinationMote[1]=0x00000002;
	
	if (TYPE_DEVICE == COORDINATOR)
	{
		
		call Timer.start(TIMER_ONE_SHOT,5000);
	}
	else
	{
		call Timer.start(TIMER_ONE_SHOT,5000);
	}

	return SUCCESS;
}

command result_t StdControl.stop() {
  
	call Mac_control.stop();
	return SUCCESS;
}

//fired when the mote starts
event result_t Timer.fired()
{
	uint8_t v_temp[2];
	
	
	if (TYPE_DEVICE == END_DEVICE)
	{
	
		my_short_address= TOS_LOCAL_ADDRESS;

		v_temp[0] = (uint8_t)(my_short_address >> 8);
		v_temp[1] = (uint8_t)(my_short_address );
		
		call MLME_SET.request(MACSHORTADDRESS,v_temp);
	
		v_temp[0] = (uint8_t)(PANID >> 8);
		v_temp[1] = (uint8_t)(PANID );
		
		call MLME_SET.request(MACPANID,v_temp);
		
		call Timer_send.start(TIMER_REPEAT,2000);

	}
	else
	{
		my_short_address= 0x0000;

		v_temp[0] = (uint8_t)(my_short_address >> 8);
		v_temp[1] = (uint8_t)(my_short_address );
		
		call MLME_SET.request(MACSHORTADDRESS,v_temp);
		
		call MLME_START.request(PANID, LOGICAL_CHANNEL, BEACON_ORDER, SUPERFRAME_ORDER,1,0,0,0,0);
		
		//call Timer_send.start(TIMER_REPEAT,8000);

	}
return SUCCESS;
}


event result_t Timer_send.fired()
{
	uint32_t SrcAddr[2];
	
	uint8_t msdu_payload[4];
	
	SrcAddr[0]=0x00000000;
	SrcAddr[1]=TOS_LOCAL_ADDRESS;
	
	//DestinationMote[0]=0x00000000;
	//DestinationMote[1]=0x0000FFFF;
	
	//call Leds.greenToggle();
	
	if(TYPE_DEVICE == COORDINATOR)
	{
	
			SrcAddr[0]=0x00000000;
			SrcAddr[1]=TOS_LOCAL_ADDRESS;
			
			if (DestinationMote[1]==0x00000002)
			{
				DestinationMote[1]=0x00000003;
			}else{
				DestinationMote[1]=0x00000002;
			}
			//printfUART("send to: %i\n", DestinationMote[1]);
			//call Leds.greenToggle();
																						//set_txoptions(ack, gts, indirect_transmission, security)
			call MCPS_DATA.request(SHORT_ADDRESS, PANID, SrcAddr, SHORT_ADDRESS, PANID, DestinationMote, 4, msdu_payload,1,set_txoptions(1,0,1,0));
	}
	else
	{
	
			DestinationMote[0]=0x00000000;
			DestinationMote[1]=0x00000000;
																								//set_txoptions(ack, gts, indirect_transmission, security)
			call MCPS_DATA.request(SHORT_ADDRESS, PANID, SrcAddr, SHORT_ADDRESS, PANID, DestinationMote, 4, msdu_payload,1,set_txoptions(1,0,0,0));
	}

return SUCCESS;
}





/*****************************************************************************************************/  
/*****************************************************************************************************/  
/**************************************MLME EVENTS****************************************************/
/*****************************************************************************************************/ 
/*****************************************************************************************************/  

/*****************************************************************************************************/  
/**************************************MLME-GTS*******************************************************/
/*****************************************************************************************************/ 

event result_t MLME_GTS.confirm(uint8_t GTSCharacteristics, uint8_t status)
{

	return SUCCESS;
}

event result_t MLME_GTS.indication(uint16_t DevAddress, uint8_t GTSCharacteristics, bool SecurityUse, uint8_t ACLEntry)
{

	
	return SUCCESS;
}

/*****************************************************************************************************/  
/**************************************MLME-START*****************************************************/
/*****************************************************************************************************/ 

event result_t MLME_START.confirm(uint8_t status)
{

	return SUCCESS;
}

/*****************************************************************************************************/  
/**************************************MLME-ASSOCIATE*************************************************/
/*****************************************************************************************************/ 
event result_t MLME_ASSOCIATE.indication(uint32_t DeviceAddress[], uint8_t CapabilityInformation, bool SecurityUse, uint8_t ACLEntry)
{

	return SUCCESS;
}

event result_t MLME_ASSOCIATE.confirm(uint16_t AssocShortAddress, uint8_t status)
{
	return SUCCESS;
}

/*****************************************************************************************************/  
/**************************************MLME-DISASSOCIATE**********************************************/
/*****************************************************************************************************/ 
event result_t MLME_DISASSOCIATE.indication(uint32_t DeviceAddress[], uint8_t DisassociateReason, bool SecurityUse, uint8_t ACLEntry)
{
	return SUCCESS;
}
  
event result_t MLME_DISASSOCIATE.confirm(uint8_t status)
{
	return SUCCESS;
}

/*****************************************************************************************************/  
/**************************************MLME-BEACON NOTIFY*********************************************/
/*****************************************************************************************************/ 

event result_t MLME_BEACON_NOTIFY.indication(uint8_t BSN,PANDescriptor pan_descriptor, uint8_t PenAddrSpec, uint8_t AddrList, uint8_t sduLength, uint8_t sdu[])
{
	
	beacon_present = 1;
	
	return SUCCESS;
}

/*****************************************************************************************************/  
/***********************			MLME-SYNC_LOSS				**************************************/
/*****************************************************************************************************/ 

event result_t MLME_SYNC_LOSS.indication(uint8_t LossReason)
{
	

	return SUCCESS;
}

/*****************************************************************************************************/  
/*************************			MLME-RESET			  ********************************************/
/*****************************************************************************************************/ 
event result_t MLME_RESET.confirm(uint8_t status)
{

	return SUCCESS;
}

/*****************************************************************************************************/  
/*************************			MLME-SCAN			   *******************************************/
/*****************************************************************************************************/ 

event result_t MLME_SCAN.confirm(uint8_t status,uint8_t ScanType, uint32_t UnscannedChannels, uint8_t ResultListSize, uint8_t EnergyDetectList[], SCAN_PANDescriptor PANDescriptorList[])
{
 printfUART("MLME_SCAN.confirm\n", "");
  return SUCCESS;
}

/*****************************************************************************************************/  
/**************************			MLME-COMM_STATUS			**************************************/
/*****************************************************************************************************/ 

event result_t MLME_COMM_STATUS.indication(uint16_t PANId,uint8_t SrcAddrMode, uint32_t SrcAddr[], uint8_t DstAddrMode, uint32_t DstAddr[], uint8_t status)
{

   return SUCCESS;
}
/*****************************************************************************************************/  
/*************************			MLME-GET			    ******************************************/
/*****************************************************************************************************/ 
event result_t MLME_GET.confirm(uint8_t status,uint8_t PIBAttribute, uint8_t PIBAttributeValue[])
{

  return SUCCESS;
}
/*****************************************************************************************************/  
/**********************				  MLME-SET		  	    ******************************************/
/*****************************************************************************************************/ 
event result_t MLME_SET.confirm(uint8_t status,uint8_t PIBAttribute)
{

  return SUCCESS;
}
/*****************************************************************************************************/  
/**********************				  MLME-POLL		  	    ******************************************/
/*****************************************************************************************************/ 
event result_t MLME_POLL.confirm(uint8_t status)
{

  return SUCCESS;
}



/*****************************************************************************************************/  
/*****************************************************************************************************/  
/****************					MCPS EVENTS 				 *************************************/
/*****************************************************************************************************/ 
/*****************************************************************************************************/  


/*****************************************************************************************************/  
/*********************					MCPS-DATA 		  	   ***************************************/
/*****************************************************************************************************/ 
event result_t MCPS_DATA.confirm(uint8_t msduHandle, uint8_t status)
{
	
return SUCCESS;
}  
event result_t MCPS_DATA.indication(uint16_t SrcAddrMode, uint16_t SrcPANId, uint32_t SrcAddr[2], uint16_t DstAddrMode, uint16_t DestPANId, uint32_t DstAddr[2], uint16_t msduLength,uint8_t msdu[100],uint16_t mpduLinkQuality, uint16_t SecurityUse, uint16_t ACLEntry)
{
	call Leds.greenToggle();
	
return SUCCESS;
}
/*****************************************************************************************************/  
/*************************			MCPS-PURGE 			  		 *************************************/
/*****************************************************************************************************/ 
event result_t MCPS_PURGE.confirm(uint8_t msduHandle, uint8_t status)
{

	return SUCCESS;
}

/*****************************************************************************************************/  
/***********************			OTHER FUNCTIONS 			**************************************/
/*****************************************************************************************************/ 


}

⌨️ 快捷键说明

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