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

📄 channel.cc

📁 fso antenna model for ns2
💻 CC
📖 第 1 页 / 共 3 页
字号:
}voidFSOWirelessChannel::removeNodeFromList(MobileNode *mn) {		MobileNode *tmp;	// Find node in list	for (tmp = xListHead_; tmp->nextX_ != NULL; tmp=tmp->nextX_) {		if (tmp == mn) {			if (tmp == xListHead_) {				xListHead_ = tmp->nextX_;				if (tmp->nextX_ != NULL)					tmp->nextX_->prevX_ = NULL;			} else if (tmp->nextX_ == NULL) 				tmp->prevX_->nextX_ = NULL;			else {				tmp->prevX_->nextX_ = tmp->nextX_;				tmp->nextX_->prevX_ = tmp->prevX_;			}			numNodes_--;			return;		}	}	fprintf(stderr, "Channel: node not found in list\n");}voidFSOWirelessChannel::sortLists(void) {	bool flag = true;	MobileNode *m, *q;	sorted_ = true;		fprintf(stderr, "SORTING LISTS ...");	/* Buble sort algorithm */	// SORT x-list	while(flag) {		flag = false;		m = xListHead_;		while (m != NULL){			if(m->nextX_ != NULL)				if ( m->X() > m->nextX_->X() ){					flag = true;					//delete_after m;					q = m->nextX_;					m->nextX_ = q->nextX_;					if (q->nextX_ != NULL)						q->nextX_->prevX_ = m;			    					//insert_before m;					q->nextX_ = m;					q->prevX_ = m->prevX_;					m->prevX_ = q;					if (q->prevX_ != NULL)						q->prevX_->nextX_ = q;					// adjust Head of List					if(m == xListHead_) 						xListHead_ = m->prevX_;				}			m = m -> nextX_;		}	}		fprintf(stderr, "DONE!\n");}voidFSOWirelessChannel::updateNodesList(class MobileNode *mn, double oldX) {		MobileNode* tmp;	double X = mn->X();	bool skipX=false;		if(!sorted_) {		sortLists();		return;	}		/* xListHead cannot be NULL here (they are created during creation of mobilenode) */		/***  DELETE ***/	// deleting mn from x-list	if(mn->nextX_ != NULL) {		if(mn->prevX_ != NULL){			if((mn->nextX_->X() >= X) && (mn->prevX_->X() <= X)) skipX = true; // the node doesn't change its position in the list			else{				mn->nextX_->prevX_ = mn->prevX_;				mn->prevX_->nextX_ = mn->nextX_;			}		}				else{			if(mn->nextX_->X() >= X) skipX = true; // skip updating the first element			else{				mn->nextX_->prevX_ = NULL;				xListHead_ = mn->nextX_;			}		}	}		else if(mn->prevX_ !=NULL){		if(mn->prevX_->X() <= X) skipX = true; // skip updating the last element		else mn->prevX_->nextX_ = NULL;	}	/*** INSERT ***/	//inserting mn in x-list	if(!skipX){		if(X > oldX){						for(tmp = mn; tmp->nextX_ != NULL && tmp->nextX_->X() < X; tmp = tmp->nextX_);			//fprintf(stdout,"Scanning the element addr %d X=%0.f, next addr %d X=%0.f\n", tmp, tmp->X(), tmp->nextX_, tmp->nextX_->X());			if(tmp->nextX_ == NULL) { 				//fprintf(stdout, "tmp->nextX_ is NULL\n");				tmp->nextX_ = mn;				mn->prevX_ = tmp;				mn->nextX_ = NULL;			} 			else{ 				//fprintf(stdout, "tmp->nextX_ is not NULL, tmp->nextX_->X()=%0.f\n", tmp->nextX_->X());				mn->prevX_ = tmp->nextX_->prevX_;				mn->nextX_ = tmp->nextX_;				tmp->nextX_->prevX_ = mn;  					tmp->nextX_ = mn;			} 		}		else{			for(tmp = mn; tmp->prevX_ != NULL && tmp->prevX_->X() > X; tmp = tmp->prevX_);				//fprintf(stdout,"Scanning the element addr %d X=%0.f, prev addr %d X=%0.f\n", tmp, tmp->X(), tmp->prevX_, tmp->prevX_->X());			if(tmp->prevX_ == NULL) {				//fprintf(stdout, "tmp->prevX_ is NULL\n");				tmp->prevX_ = mn;				mn->nextX_ = tmp;				mn->prevX_ = NULL;				xListHead_ = mn;			} 			else{				//fprintf(stdout, "tmp->prevX_ is not NULL, tmp->prevX_->X()=%0.f\n", tmp->prevX_->X());				mn->nextX_ = tmp->prevX_->nextX_;				mn->prevX_ = tmp->prevX_;				tmp->prevX_->nextX_ = mn;  					tmp->prevX_ = mn;					}		}	}}MobileNode **FSOWirelessChannel::getAffectedNodes(Phy *tifp, int *numAffectedNodes){	int n = 0;	MobileNode *tmp, **list, **tmpList, *tmp2;	if (xListHead_ == NULL) {		*numAffectedNodes=-1;		fprintf(stderr, "xListHead_ is NULL when trying to send!!!\n");		return NULL;	}		// First allocate as much as possibly needed	tmpList = new MobileNode*[numNodes_];		tmp2 = ((MobileNode *)tifp->node());		for(tmp = ((MobileNode *)tifp->node())->prevX_; tmp != NULL; tmp=tmp->prevX_)	{		if(nodeIsLOS(tifp,tmp))		{			if(n == 0)			{				tmpList[n++] = tmp;			}			else			{				if(calculateDistance(tmp2,tmp) < calculateDistance(tmp2,tmpList[n-1]))				{					tmpList[n-1] = tmp;				}			}		}	}	for(tmp = ((MobileNode *)tifp->node())->nextX_; tmp != NULL; tmp=tmp->nextX_)	{		if(nodeIsLOS(tifp,tmp))		{			if(n == 0)			{				tmpList[n++] = tmp;			}			else			{				if(calculateDistance(tmp2,tmp) < calculateDistance(tmp2,tmpList[n-1]))				{					tmpList[n-1] = tmp;				}			}		}	}		/*if(n != 0)	{		cout << tmp2->X() << " " << tmp2->Y() << " sending to " << tmpList[0]->X() << " " << tmpList[0]->Y() << endl;	}*/		list = new MobileNode*[n];	memcpy(list, tmpList, n * sizeof(MobileNode *));	delete [] tmpList;	//cout << n << endl;	*numAffectedNodes = n;	return list;}MobileNode **FSOWirelessChannel::getAffectedNodes(MobileNode *mn, double radius,				  int *numAffectedNodes){	double xmin, xmax, ymin, ymax;	int n = 0;	MobileNode *tmp, **list, **tmpList;	if (xListHead_ == NULL) {		*numAffectedNodes=-1;		fprintf(stderr, "xListHead_ is NULL when trying to send!!!\n");		return NULL;	}		xmin = mn->X() - radius;	xmax = mn->X() + radius;	ymin = mn->Y() - radius;	ymax = mn->Y() + radius;		// First allocate as much as possibly needed	tmpList = new MobileNode*[numNodes_];		/*for(tmp = xListHead_; tmp != NULL; tmp = tmp->nextX_) tmpList[n++] = tmp;	for(int i = 0; i < n; ++i)		if(tmpList[i]->speed()!=0.0 && (Scheduler::instance().clock() -						tmpList[i]->getUpdateTime()) > XLIST_POSITION_UPDATE_INTERVAL )			tmpList[i]->update_position();*/		for(tmp = mn; tmp != NULL && tmp->X() >= xmin; tmp=tmp->prevX_)		if(tmp->Y() >= ymin && tmp->Y() <= ymax){			tmpList[n++] = tmp;		}	for(tmp = mn->nextX_; tmp != NULL && tmp->X() <= xmax; tmp=tmp->nextX_){		if(tmp->Y() >= ymin && tmp->Y() <= ymax){			tmpList[n++] = tmp;		}	}		list = new MobileNode*[n];	memcpy(list, tmpList, n * sizeof(MobileNode *));	delete [] tmpList;		*numAffectedNodes = n;	return list;}boolFSOWirelessChannel::nodeIsLOS(Phy *TxInterface, MobileNode * RxNode){	/* The angular orientation of the receiver */	long double T_phi;/*Angle between NLOS of antenna2 and R (To be found out)*/	/*R is the Vector between the receiver from the transmitter*/	long double R; /*Absolute distance between Tx and Rx*/	long double Mod_NLOST; /*Absolute length of NLOS2*/	double Tx_Angle; //Transmission angle	//double Rx_Angle;	/* Co-ordinates of both the communicating antennas and their NLOS's*/	long double RX_CoOrd;	long double RY_CoOrd;	long double RZ_CoOrd; 	long double TX_CoOrd; 	long double TY_CoOrd; 	long double TZ_CoOrd; 	long double TX_NLOS;	long double TY_NLOS; 	long double TZ_NLOS;	long double Roe;	RX_CoOrd = RxNode->X();	RY_CoOrd = RxNode->Y();	RZ_CoOrd = RxNode->Z();	TX_CoOrd = ((MobileNode*)TxInterface->node())->X();	TY_CoOrd = ((MobileNode*)TxInterface->node())->Y();	TZ_CoOrd = ((MobileNode*)TxInterface->node())->Z();	/*	TX_NLOS = ((FSOAntenna *)(((FSOWirelessPhy *)TxInterface)->getAntenna()))->getXNormal();	TY_NLOS = ((FSOAntenna *)(((FSOWirelessPhy *)TxInterface)->getAntenna()))->getYNormal();	TZ_NLOS = ((FSOAntenna *)(((FSOWirelessPhy *)TxInterface)->getAntenna()))->getZNormal();	Tx_Angle = ((FSOAntenna *)(((FSOWirelessPhy *)TxInterface)->getAntenna()))->getTx_Angle();	*/		TX_NLOS = ((FSOAntenna *)(((WirelessPhy *)TxInterface)->getAntenna()))->getXNormal();	TY_NLOS = ((FSOAntenna *)(((WirelessPhy *)TxInterface)->getAntenna()))->getYNormal();	TZ_NLOS = ((FSOAntenna *)(((WirelessPhy *)TxInterface)->getAntenna()))->getZNormal();	Tx_Angle = ((FSOAntenna *)(((WirelessPhy *)TxInterface)->getAntenna()))->getTx_Angle();	/*Get the LOS distance from the co-orinates*/	R = sqrt(square(TX_CoOrd - RX_CoOrd) + square(TY_CoOrd - RY_CoOrd) + square(TZ_CoOrd - RZ_CoOrd));	Mod_NLOST =  sqrt(square(TX_NLOS) + square(TY_NLOS) + square(TZ_NLOS));	Roe = ((RX_CoOrd - TX_CoOrd)*TX_NLOS + (RY_CoOrd - TY_CoOrd)*TY_NLOS + (RZ_CoOrd - TZ_CoOrd)*TZ_NLOS)/(R * Mod_NLOST);	if(Roe < -1)	{		T_phi = PI;	}	else if(Roe > 1)	{		T_phi = 0.0;	}	else	{		T_phi = acos(Roe);	}	if(T_phi < (Tx_Angle/2.0))	{		return true;	}	else	{		return false;	}}doubleFSOWirelessChannel::calculateDistance(MobileNode * Tx, MobileNode * Rx){	return sqrt(square(Tx->X() - Rx->X()) + square(Tx->Y() - Rx->Y()) + square(Tx->Z() - Rx->Z()));} /* Only to be used with mobile nodes (WirelessPhy). * NS-2 at its current state support only a flat (non 3D) movement of nodes, * so we assume antenna heights do not change for the dureation of * a simulation. * Another assumption - all nodes have the same wireless interface, so that * the maximum distance, corresponding to CST (at max transmission power  * level) stays the same for all nodes. */voidFSOWirelessChannel::calcHighestAntennaZ(Phy *tifp){       double highestZ = 0;       Phy *n;        for(n = ifhead_.lh_first; n; n = n->nextchnl()) { 	     			          if(((WirelessPhy *)n)->getAntennaZ() > highestZ)          	highestZ = ((WirelessPhy *)n)->getAntennaZ();       }        highestAntennaZ_ = highestZ;       WirelessPhy *wifp = (WirelessPhy *)tifp;       distCST_ = wifp->getDist(wifp->getCSThresh(), wifp->getPt(), 1.0, 1.0,				highestZ , highestZ, wifp->getL(),				wifp->getLambda());  }	doubleFSOWirelessChannel::get_pdelay(Node* tnode, Node* rnode){	// Scheduler	&s = Scheduler::instance();	MobileNode* tmnode = (MobileNode*)tnode;	MobileNode* rmnode = (MobileNode*)rnode;	double propdelay = 0;		propdelay = tmnode->propdelay(rmnode);	assert(propdelay >= 0.0);	if (propdelay == 0.0) {		/* if the propdelay is 0 b/c two nodes are on top of 		   each other, move them slightly apart -dam 7/28/98 */		propdelay = 2 * DBL_EPSILON;		//printf ("propdelay 0: %d->%d at %f\n",		//	tmnode->address(), rmnode->address(), s.clock());	}	return propdelay;}// end FSO RPI Extensions

⌨️ 快捷键说明

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