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

📄 opnetwork_capture_mode_power_ref.ps.c

📁 基于OPNET的网络仿真程序,为Opnet网络仿真书籍的实例
💻 C
字号:
/* opnetwork_capture_mode_power_ref.ps.c */                                                       
/*
/****************************************/
/*		  Copyright (c) 1993			*/
/*			by MIL 3, 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 */


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

void
opnetwork_capture_mode_power_ref (pkptr)
	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;
	double		in_band_tx_power, band_max, band_min;
	double		rx_base_freq, rx_bandwidth;

	/** Compute the average power in Watts of the		**/
	/** signal associated with a transmitted packet.	**/
	FIN (opnetwork_capture_mode_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);
			}
		}

	/* 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);

	/* 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 + -