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

📄 opnetwork_closure_stats.ps.c

📁 基于OPNET的无线电网络仿真
💻 C
字号:
/* dra_closure.ps.c */                                                       
/* Default link closure model for radio link Transceiver Pipeline */

/****************************************/
/*		  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 <math.h>
#include <opnet.h>


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

#define EARTH_RADIUS		6.378E+06
#define RADIUS_RATIO		1.6329932


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

void
opnetwork_closure_stats (pkptr)
	Packet*		pkptr;
	{
	int			occlude;
	double		tx_x, tx_y, tx_z, rx_x, rx_y, rx_z;
	double		dif_x, dif_y, dif_z, dot_rx_dif;
	double		dot_tx_dif, rx_mag, dif_mag, cos_rx_dif, sin_rx_dif;
	double		orth_drop;

	/** Compute whether or not the packet's transmitter	**/ 
	/** can reach the receiver of interest.				**/
	FIN (opnetwork_closure_stats (pkptr));

	/* dra_closure implements a 'ray-tracing' closure model for radio	*/
	/* transmissions, testing the line segment joining tx and rx for	*/
	/* intersection with the earth (modeled as a sphere).  This default	*/
	/* model does not account for any wave bending.						*/

	/* Obtain the cartesian-geocentric coordinates for both nodes. */
	tx_x = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_GEO_X);
	tx_y = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_GEO_Y);
	tx_z = op_td_get_dbl (pkptr, OPC_TDA_RA_TX_GEO_Z);

	rx_x = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_GEO_X);
	rx_y = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_GEO_Y);
	rx_z = op_td_get_dbl (pkptr, OPC_TDA_RA_RX_GEO_Z);

	/* Calculate difference vector (transmitter to receiver). */
	dif_x = rx_x - tx_x;
	dif_y = rx_y - tx_y;
	dif_z = rx_z - tx_z;

	/* Calculate dot product of (rx) and (dif) vectors. */
	dot_rx_dif = rx_x*dif_x + rx_y*dif_y + rx_z*dif_z;

	/* If angle (rx, dif) > 90 deg., there is no occlusion. */
	if (dot_rx_dif <= 0.0) 
		occlude = OPC_FALSE;
	else
		{
		/* Calculate dot product of (tx) and (dif) vectors. */
		dot_tx_dif = tx_x*dif_x + tx_y*dif_y + tx_z*dif_z;

		/* If angle (tx, dif) < 90) there is no occlusion. */
		if (dot_tx_dif >= 0.0) 
			occlude = OPC_FALSE;
		else
			{
			/* Calculate magnitude of (rx) and (dif) vectors. */
			rx_mag = sqrt (rx_x*rx_x + rx_y*rx_y + rx_z*rx_z);
			dif_mag = sqrt (dif_x*dif_x + dif_y*dif_y + dif_z*dif_z);

			/* Calculate sin (rx, dif). */
			cos_rx_dif = dot_rx_dif / (rx_mag * dif_mag);
			sin_rx_dif = sqrt (1.0 - (cos_rx_dif * cos_rx_dif));

			/* Calculate length of orthogonal drop	*/
			/* from (dif) to earth center.			*/
			orth_drop = sin_rx_dif * rx_mag;

			/* The satellites are occluded iff this distance	*/
			/* is less than the earth's radius.					*/
			if (orth_drop < EARTH_RADIUS)
				occlude = OPC_TRUE;
			else
				occlude = OPC_FALSE;
			}
		}

	/* Place closure status in packet transmission data block. */
	op_td_set_int (pkptr, OPC_TDA_RA_CLOSURE,
		(occlude == OPC_FALSE) ? OPC_TRUE : OPC_FALSE);

	/**************************************************************/
	/* Remove the '#if 0' and the '#endif' lines outlining        */
	/* the following code block.                                  */
	/**************************************************************/
//#if 0 /*** DELETE THIS LINE ***/
	if (occlude == OPC_TRUE)
	{
		Objid		tx_objid, node_objid, proc_objid;
		int			i, proc_count;
		char		proc_name [255];
		Stathandle	*link_failure_lshandle;

		/* Obtain the object ID of the radio transmitter. */
		tx_objid = op_td_get_int (pkptr, OPC_TDA_RA_TX_OBJID);

		/* Obtain the object ID of the node.              */
		node_objid = op_topo_parent (tx_objid);

		/* Obtain the object ID of the stats module.      */
		proc_count = op_topo_child_count (node_objid, OPC_OBJTYPE_PROC);
		for (i = 0; i < proc_count; i++)
		{

			/* Access the ith processor module.           */
			proc_objid = op_topo_child (node_objid, OPC_OBJTYPE_PROC, i);

			/* Check to make sure that this module has    */
			/* the name "wireless_stats".                 */
			op_ima_obj_attr_get (proc_objid, "name", &proc_name);
			if (strcmp (proc_name, "wireless_stats") == 0)
			{

				/* Access the state variable that holds   */
				/* the registered statistic.              */
				link_failure_lshandle = (Stathandle*) op_ima_obj_svar_get (proc_objid, "link_failure_lshandle");

				/* Record out the link failure statistic. */
				if (link_failure_lshandle != OPC_NIL)
					op_stat_write (*link_failure_lshandle, 1.0);
			}
		}
	}
//#endif /*** DELETE THIS LINE ***/
	/**************************************************************/

	FOUT;
	}                

⌨️ 快捷键说明

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