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

📄 wlan_power.ps.c

📁 基于OPNET的无线局域网网络仿真
💻 C
字号:
/* dra_power.ps.c */                                                       
/* Default received power model for radio link Transceiver Pipeline */

/****************************************/
/*  	  Copyright (c) 1993-2000		*/
/*      by OPNET Technologies, Inc.     */
/*		(A Delaware Corporation)		*/
/*	3400 International Drive,  N.W.		*/
/*		Washington, D.C., U.S.A.		*/
/*			All Rights Reserved.		*/
/****************************************/

#include "opnet.h"
#include <math.h>


/***** constants *****/

#define C					3.0E+08			/* speed of light (m/s) */
#define SIXTEEN_PI_SQ		157.91367		/* 16 times pi-squared */

static const char*	PowI_Err_Hdr = "Error in radio power computation pipeline stage (dra_power):";


/***** pipeline procedure *****/

#if defined (__cplusplus)
extern "C"
#endif
void
wlan_power (Packet * pkptr)
	{
	double		prop_distance, rcvd_power, path_loss;
	double		tx_power, tx_base_freq, tx_bandwidth, tx_center_freq;
	double		lambda, rx_ant_gain, tx_ant_gain;
	Boolean		sig_lock;
	Objid		rx_ch_obid, rx_obid;
	double		in_band_tx_power, band_max, band_min;
	double		rx_base_freq, rx_bandwidth;
	double		rx_reception_end, pk_reception_end;

	/** Compute the average power in Watts of the		**/
	/** signal associated with a transmitted packet.	**/
	FIN (dra_power (pkptr));

	/* If the incoming packet is 'valid', it may cause the receiver to	*/
	/* lock onto it. However, if the receiving node is disabled, then	*/
	/* the channel match should be set to noise.						*/
	if (op_td_get_int (pkptr, OPC_TDA_RA_MATCH_STATUS) == OPC_TDA_RA_MATCH_VALID)
		{
		if (op_td_is_set (pkptr, OPC_TDA_RA_ND_FAIL))
			{
			/* The receiving node is disabled.  Change	*/
			/* the channel match status to noise.		*/
			op_td_set_int (pkptr, OPC_TDA_RA_MATCH_STATUS, OPC_TDA_RA_MATCH_NOISE);
			}
		else
			{
			/* The receiving node is enabled. Get the object id	*/
			/* of the receiver channel and the receiver itself.	*/
			rx_ch_obid = op_td_get_int (pkptr, OPC_TDA_RA_RX_CH_OBJID);
			rx_obid    = op_topo_parent (op_topo_parent (rx_ch_obid));

			/* Obtain the status of the receiver. If end of		*/
			/* reception time is in future then this means the	*/
			/* receiver is already busy.						*/
			op_ima_obj_attr_get (rx_obid, "reception end time", &rx_reception_end);

			/* If the receiver is already receiving another		*/
			/* packet, then the packet will now be considered	*/
			/* to be noise. This prevents simultaneous			*/
			/* reception of multiple valid packets on any given	*/
			/* radio channel and the entire radio receiver,		*/
			/* since in the	wlan nodes, all the channels use	*/
			/* the same	frequency.								*/
			if (rx_reception_end <= op_sim_time ())
				{
				/* The receiver is idle. Turn on the signal		*/
				/* lock. No need to change the status of the	*/
				/* packet, since it is valid by default.		*/
				sig_lock = OPC_BOOLINT_ENABLED;
				op_ima_obj_attr_set (rx_ch_obid, "signal lock", sig_lock);
				}
			else
				{
				/* At least one channel of the receiver is		*/
				/* busy. We will handle the current packet as	*/
				/* noise.										*/
				op_td_set_int (pkptr, OPC_TDA_RA_MATCH_STATUS, OPC_TDA_RA_MATCH_NOISE);
				}

			/* Update the reception end time for the receiver	*/
			/* based on the new packet.							*/
			pk_reception_end = op_td_get_dbl (pkptr, OPC_TDA_RA_END_RX);
			if (pk_reception_end > rx_reception_end)
				op_ima_obj_attr_set (rx_obid, "reception end time", pk_reception_end);
			}
		}

	/* Get power allotted to transmitter channel. */
	tx_power = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_POWER);

	/* Get transmission frequency in Hz. */
	tx_base_freq = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_FREQ);
	tx_bandwidth = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_BW);
	tx_center_freq = tx_base_freq + (tx_bandwidth / 2.0);

	/* Caclculate wavelength (in meters). */
	lambda = C / tx_center_freq;

	/* Get distance between transmitter and receiver (in meters). */
	prop_distance = op_td_get_dbl (pkptr, OPC_TDA_RA_START_DIST);

	/* When using TMM, the TDA OPC_TDA_RA_RCVD_POWER will already	*/
	/* have a raw value for the path loss. */
	if (op_td_is_set (pkptr, OPC_TDA_RA_RCVD_POWER))
		{
		path_loss = op_td_get_dbl (pkptr, OPC_TDA_RA_RCVD_POWER);
		}
	else
		{
		/* Compute the path loss for this distance and wavelength. */
		if (prop_distance > 0.0)
			{
			path_loss = (lambda * lambda) / 
				(SIXTEEN_PI_SQ * prop_distance * prop_distance);
			}
		else
			path_loss = 1.0;
		}

	/* Determine the receiver bandwidth and base frequency. */
	rx_base_freq = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_FREQ);
	rx_bandwidth = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_BW);

	/* Use these values to determine the band overlap with the transmitter.	*/
	/* Note that if there were no overlap at all, the packet would already	*/
	/* have been filtered by the channel match stage.						*/

	/* The base of the overlap band is the highest base frequency. */
	if (rx_base_freq > tx_base_freq) 
		band_min = rx_base_freq;
	else
		band_min = tx_base_freq;
	
	/* The top of the overlap band is the lowest end frequency. */
	if (rx_base_freq + rx_bandwidth > tx_base_freq + tx_bandwidth)
		band_max = tx_base_freq + tx_bandwidth;
	else
		band_max = rx_base_freq + rx_bandwidth;

	/* Compute the amount of in-band transmitter power. */
	in_band_tx_power = tx_power * (band_max - band_min) / tx_bandwidth;

	/* Get antenna gains (raw form, not in dB). */
	tx_ant_gain = pow (10.0, op_td_get_dbl (pkptr, OPC_TDA_RA_TX_GAIN) / 10.0);
	rx_ant_gain = pow (10.0, op_td_get_dbl (pkptr, OPC_TDA_RA_RX_GAIN) / 10.0);

	/* Calculate received power level. */
	rcvd_power = in_band_tx_power * tx_ant_gain * path_loss * rx_ant_gain;

	/* Assign the received power level (in Watts) */
	/* to the packet transmission data attribute. */
	op_td_set_dbl (pkptr, OPC_TDA_RA_RCVD_POWER, rcvd_power);

	FOUT;
	}

⌨️ 快捷键说明

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