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

📄 backoff exit execs

📁 opnet无线网络编程
💻
字号:
/* Lock the mutex that serializes accessing the roaming related		*/
/* information of this MAC. 										*/
op_prg_mt_mutex_lock (roam_state_ptr->roam_info_mutex, 0);

/* Call the interrupt processing routine for each interrupt.		*/
wlan_interrupts_process();

/* Set the number of slots to zero, once the backoff is completed.	*/
if (BACKOFF_COMPLETED)
	{
	backoff_slots = BACKOFF_SLOTS_UNSET;

	// if the backoff is complete reset the flags indicating that a backoff is pending
	// and the flag indicating a backoff was scheduled
	backoff_pending = OPC_FALSE;
	wsn_interrupt_backoff = OPC_FALSE;
	}
else if (CW_COMPLETED)
	{
	backoff_slots = BACKOFF_SLOTS_UNSET;
	
	// if the backoff is complete reset the flags indicating that a backoff is pending
	// and the flag indicating a CW was scheduled
	backoff_pending = OPC_FALSE;
	wsn_interrupt_cw = OPC_FALSE;
	
	/* Reset the contention window flags to enable future			*/
	/* transmissions.												*/
	wlan_flags->cw_required = OPC_FALSE;
	wlan_flags->perform_cw  = OPC_FALSE;
// wsn
	wsn_deference_cw = OPC_FALSE;
	}

/* Pause the backoff procedure if our receiver just became busy or	*/
/* if we received a self interrupt indicating the time to send a	*/
/* Beacon frame for a new contention free period.					*/
if ((sleep==1) || RECEIVER_BUSY_HIGH || (!wlan_flags->receiver_busy && intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_Beacon_Tx_Time)) 
	{
	
	/* Computing remaining backoff slots for next iteration.		*/
	backoff_slots =  ceil ((intrpt_time - current_time - PRECISION_RECOVERY) / slot_time);
	
	// wsn WARNING
	if (backoff_slots < 0)
		backoff_slots = 0;
	
	/* Don't cancel the end-of-backoff interrupt if we have already	*/
	/* completed all the slots of the back-off.						*/
	if (op_ev_valid (backoff_elapsed_evh) == OPC_TRUE && (backoff_slots > 0.0 || !RECEIVER_BUSY_HIGH))
		{
		/* Clear the self interrupt as station needs to defer.		*/
		op_ev_cancel (backoff_elapsed_evh);
		
		// cancel the backoff pending flag and the flags indicating what kind
		// of backoff interrupt was scheduled
		backoff_pending = OPC_FALSE;
		wsn_interrupt_cw = OPC_FALSE;
		wsn_interrupt_backoff = OPC_FALSE;
		
		/* Disable perform cw flag because the station will not		*/
		/* backoff using contention window.							*/
		wlan_flags->perform_cw  = OPC_FALSE;

		// reset the schedule CW flag, used to restore the flag status when 
		// a node wakes up
		wsn_deference_cw = OPC_FALSE;
		
		}

	/* If the remaining backoff slots were computed as "0" slot		*/
	/* then we are experiencing a special case: we started 			*/
	/* receiving a transmission at the exact same time when we will	*/
	/* complete our backoff and start our own transmission. In such	*/
	/* cases we ignore the reception and continue with our planned	*/
	/* transmission for the accuracy of the simulation model,		*/
	/* because these two events are happening at the exact same		*/
	/* time and	their execution order should not change the overall	*/
	/* behavior of the MAC. Similarly, this will take us to IDLE	*/
	/* state in the next interrupt, if the reception started at the	*/
	/* exact time when we would complete our CW period and move		*/
	/* back to IDLE because of empty high layer buffer.				*/
	if (backoff_slots == 0.0 && intrpt_type == OPC_INTRPT_STAT)
		wlan_flags->forced_bk_end = OPC_TRUE;
	}

if (BACK_TO_DEFER)
	{
	
	if ( op_ev_valid (deference_evh) == OPC_TRUE)
		{
			/* Cancel the current event and schedule a new one.			*/
			op_ev_cancel (deference_evh);
		}
	
	wlan_schedule_deference ();
	}
	
// energy calculation check
#ifndef OPD_NO_DEBUG

if ((op_sim_time() > wsn_test_time) && (my_address == wsn_test_address || my_address == wsn_test_address_2) )
	{
	printf("Node <%d> in Backoff at time %e \n", my_address, op_sim_time());

	if (BACK_TO_DEFER)
		printf("Node <%d> is exiting Backoff and NOT calculating E before going BACK_TO_DEFER\n", my_address);
	else if (PERFORM_TRANSMIT)
		printf("Node <%d> is exiting Backoff and IS calculating E before going to transmit\n", my_address);
	else if (SLEEP_NOW)
		printf("Node <%d> is exiting Backoff and IS calculating E before going to SLEEP\n", my_address);
	else if (BACK_TO_IDLE)
		printf("Node <%d> is exiting Backoff and NOT calculating E before going to IDLE\n", my_address);
	else if (SCAN_AFTER_CW)
		printf("Node <%d> is exiting Backoff and NOT calculating E before going to SCAN\n", my_address);
	}

#endif

// Updates energy on final transition out of BACKOFF State
if (PERFORM_TRANSMIT)
	Update_Energy();

⌨️ 快捷键说明

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