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

📄 cust_rxgroup.ps.c

📁 基于OPNET的网络仿真程序,为Opnet网络仿真书籍的实例
💻 C
字号:
/* cust_rxgroup.ps.c */                                                       
/* Custom receiver group 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"


#if defined (__cplusplus)
extern "C"
#endif
int
cust_rxgroup (Objid tx_obid, Objid rx_obid)	
	{
	int eligible_rx = OPC_FALSE;	/* flag that indicates if an eligible receiver */
	int in_range = 0;	/* flag that indicates if the rxch is in range of the txch */
	double radius;	/* tranmission radius of the transmitter channel */
	double distance;	/* distance between the transmitter channel and receiver channel */
	double tx_x, tx_y, tx_z, rx_x, rx_y, rx_z;	/* variables to store txch and rxch locations */
	double latitude, longitude, altitude;
	Objid tx_node;	/* node object ID that contains the given transmitter channel */
	Objid rx_node;	/* node object ID that contains the given receiver channel */
	
	/** Determine the potential for communication between	**/
	/** given transmitter and receiver channel objects.		**/
	FIN (cust_rxgroup (tx_obid, rx_obid));
   
	/* Determine the object IDs of the transmitter and receiver nodes */
	tx_node = op_topo_parent (op_topo_parent (op_topo_parent (tx_obid)));
	rx_node = op_topo_parent (op_topo_parent (op_topo_parent (rx_obid)));
	
	/* Check if the transmitter and receiver are part of the same node. */
	/* If not, then check if receiver channel objects are within a given distance (radius) */
	/* from the transmitter channel.  If the receivers are too far away, then */
	/* they will not be sent packets. */
	if (tx_node != rx_node)
		{
		/* Get radius attribute value from process model */
		op_ima_obj_attr_get (op_topo_child (tx_node, OPC_OBJTYPE_PROC, 0), "Transmission Radius", &radius);
		/* Get locations of transmitter channel and receiver channel */
		op_ima_obj_pos_get (tx_node, &latitude, &longitude, &altitude, &tx_x, &tx_y, &tx_z);
		op_ima_obj_pos_get (rx_node, &latitude, &longitude, &altitude, &rx_x, &rx_y, &rx_z);
		
		/*
		printf("tx_node: %f %f %f\nrx_node: %f %f %f\n", tx_x, tx_y, tx_z, rx_x, rx_y, rx_z);
		printf("%f %f %f\n", fabs(tx_x-rx_x), fabs(tx_y-rx_y), fabs(tx_z-rx_z));
		printf("%f %f %f\n", (fabs(tx_x-rx_x))*(fabs(tx_x-rx_x)), (fabs(tx_y-rx_y))*(fabs(tx_y-rx_y)), (fabs(tx_z-rx_z))*(fabs(tx_z-rx_z)));
		printf("%f\n", (fabs(tx_x-rx_x))*(fabs(tx_x-rx_x)) + (fabs(tx_y-rx_y))*(fabs(tx_y-rx_y)) + (fabs(tx_z-rx_z))*(fabs(tx_z-rx_z)));
		*/
		
		/* Calculate distance between transmitter channel and receiver channel */
		distance = sqrt((fabs(tx_x-rx_x))*(fabs(tx_x-rx_x)) + (fabs(tx_y-rx_y))*(fabs(tx_y-rx_y)) + (fabs(tx_z-rx_z))*(fabs(tx_z-rx_z)));
		
		/*
		printf("Radius = %f\tDistance = %f\n", radius, distance);
		*/
		
		if (distance < radius)
			{
			/*
			printf("ELIGIBLE RX!\n");
			*/
			eligible_rx = OPC_TRUE;
			}
		else
			eligible_rx = OPC_FALSE;
		}
	
	FRET (eligible_rx);
	}                

⌨️ 快捷键说明

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