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

📄 wireless-phy.cc

📁 这个市一个ns环境下的leach算法!大家可以多下在啊!我想要一个matlab环境下的概算法!
💻 CC
📖 第 1 页 / 共 2 页
字号:
			    fprintf(stderr,"act_tx = %lf, tx = %lf\n", actual_txtime, txtime);		    }		    */		   // Sanity check		   double temp = max(NOW,last_send_time_);		   /*		   if (NOW < last_send_time_) {			   fprintf(stderr,"Argggg !! Overlapping transmission. NOW %lf last %lf temp %lf\n", NOW, last_send_time_, temp);		   }		   */		   		   double begin_adjust_time = min(channel_idle_time_, temp);		   double finish_adjust_time = min(channel_idle_time_, NOW+txtime);		   double gap_adjust_time = finish_adjust_time - begin_adjust_time;		   if (gap_adjust_time < 0.0) {			   fprintf(stderr,"What the heck ! negative gap time.\n");		   }		   if ((gap_adjust_time > 0.0) && (status_ == RECV)) {			   em()->DecrTxEnergy(gap_adjust_time,					      Pt_consume_-Pr_consume_);		   }		   em()->DecrTxEnergy(actual_txtime,Pt_consume_);		   if (end_time > channel_idle_time_) {			   status_ = SEND;		   }									   last_send_time_ = NOW+txtime;		   channel_idle_time_ = end_time;		   update_energy_time_ = end_time;		   if (em()->energy() <= 0) {			   em()->setenergy(0);			   ((MobileNode*)node())->log_energy(0);		   }		} else {			Packet::free(p);			return;		}	}	/*	 *  Stamp the packet with the interface arguments	 */	p->txinfo_.stamp((MobileNode*)node(), ant_->copy(), Pt_, lambda_);	// Send the packet	channel_->recv(p, this);}int WirelessPhy::sendUp(Packet *p){	/*	 * Sanity Check	 */	assert(initialized());	PacketStamp s;	double Pr;	int pkt_recvd = 0;#ifdef MIT_uAMPS  hdr_cmn *ch = HDR_CMN(p);  hdr_rca *rca_hdr = HDR_RCA(p);  /*    * Record when this packet ends and its code.   */  int code = rca_hdr->get_code();  cs_end_[code] = Scheduler::instance().clock() + txtime(p);  /*    * If the node is asleep, drop the packet.    */  if (sleep_) {      //printf("Sleeping node... carrier sense ends at %f\n", cs_end_);      //fflush(stdout);      pkt_recvd = 0;      goto DONE;  } #endif 	// if the node is in sleeping mode, drop the packet simply	if (em()) 		if (em()->sleep() || (em()->node_on() != true)) {			pkt_recvd = 0;			goto DONE;		}		// if the energy goes to ZERO, drop the packet simply	if (em()) {		if (em()->energy() <= 0) {			pkt_recvd = 0;			goto DONE;		}	}	if(propagation_) {		s.stamp((MobileNode*)node(), ant_, 0, lambda_);		Pr = propagation_->Pr(&p->txinfo_, &s, this);		if (Pr < CSThresh_) {			pkt_recvd = 0;			goto DONE;		}		if (Pr < RXThresh_) {			/*			 * We can detect, but not successfully receive			 * this packet.			 */			hdr_cmn *hdr = HDR_CMN(p);			hdr->error() = 1;#if DEBUG > 3			printf("SM %f.9 _%d_ drop pkt from %d low POWER %e/%e\n",			       Scheduler::instance().clock(), node()->index(),			       p->txinfo_.getNode()->index(),			       Pr,RXThresh);#endif		}	}	if(modulation_) {		hdr_cmn *hdr = HDR_CMN(p);		hdr->error() = modulation_->BitError(Pr);	}	#ifdef MIT_uAMPS  /*    * Only remove energy from nodes that are awake and not currently   * transmitting a packet.   */  if (Scheduler::instance().clock() >= time_finish_rcv_) {    PXcvr_ = EXcvr_ * bandwidth_;    if (energy_)    {       if (energy_->remove(pktEnergy((double)0, PXcvr_,ch->size())) != 0)        alive_ = 0;    }    time_finish_rcv_ = Scheduler::instance().clock() + txtime(p);  }  /*   * Determine approximate distance of node transmitting node    * from received power.   */  double hr, ht;        // height of recv and xmit antennas  double rX, rY, rZ;    // receiver location  double d1, d2;  double crossover_dist, Pt, M;  node_->getLoc(&rX, &rY, &rZ);  hr = rZ + ant_->getZ();  ht = hr;              // assume transmitting node antenna at same height  crossover_dist = sqrt((16 * PI * PI * L_ * ht * ht * hr * hr)                             / (lambda_ * lambda_));  Pt = p->txinfo_.getTxPr();  M = lambda_ / (4 * PI);  d1 = sqrt( (Pt * M * M) / (L_ * Pr) );  d2 = sqrt(sqrt( (Pt * hr * hr * ht * ht) / Pr) );  if (d1 < crossover_dist)    dist_ = d1;  else    dist_ = d2;  rca_hdr->dist_est() = (int) ceil(dist_);#endif	/*	 * The MAC layer must be notified of the packet reception	 * now - ie; when the first bit has been detected - so that	 * it can properly do Collision Avoidance / Detection.	 */	pkt_recvd = 1;DONE:	p->txinfo_.getAntenna()->release();	/* WILD HACK: The following two variables are a wild hack.	   They will go away in the next release...	   They're used by the mac-802_11 object to determine	   capture.  This will be moved into the net-if family of 	   objects in the future. */	p->txinfo_.RxPr = Pr;	p->txinfo_.CPThresh = CPThresh_;	/*	 * Decrease energy if packet successfully received	 */	if(pkt_recvd && em()) {		//double rcvtime = (8. * hdr_cmn::access(p)->size())/bandwidth_;		double rcvtime = hdr_cmn::access(p)->txtime();		// no way to reach here if the energy level < 0				/*		  node()->add_rcvtime(rcvtime);	  		  em()->DecrRcvEnergy(rcvtime,Pr_consume_);		*/		double start_time = max(channel_idle_time_, NOW);		double end_time = max(channel_idle_time_, NOW+rcvtime);		double actual_rcvtime = end_time-start_time;		if (start_time > update_energy_time_) {			em()->DecrIdleEnergy(start_time-update_energy_time_,					     P_idle_);			update_energy_time_ = start_time;		}				em()->DecrRcvEnergy(actual_rcvtime,Pr_consume_);		if (end_time > channel_idle_time_) {			status_ = RECV;		}		channel_idle_time_ = end_time;		update_energy_time_ = end_time;		/*		  hdr_diff *dfh = HDR_DIFF(p);		  printf("Node %d receives (%d, %d, %d) energy %lf.\n",		  node()->address(), dfh->sender_id.addr_, 		  dfh->sender_id.port_, dfh->pk_num, node()->energy());		*/				if (em()->energy() <= 0) {  			// saying node died			em()->setenergy(0);			((MobileNode*)node())->log_energy(0);		}	}		return pkt_recvd;}voidWirelessPhy::node_on(){        if (em() == NULL) 	    return;	   	if (NOW > update_energy_time_) {      	    update_energy_time_ = NOW;   	}}void WirelessPhy::node_off(){	if (em() == NULL)            return;        if (NOW > update_energy_time_) {            em()->DecrIdleEnergy(NOW-update_energy_time_,                                P_idle_);            update_energy_time_ = NOW;	}}voidWirelessPhy::dump(void) const{	Phy::dump();	fprintf(stdout,		"\tPt: %f, Gt: %f, Gr: %f, lambda: %f, L: %f\n",		Pt_, ant_->getTxGain(0,0,0,lambda_), ant_->getRxGain(0,0,0,lambda_), lambda_, L_);	//fprintf(stdout, "\tbandwidth: %f\n", bandwidth_);	fprintf(stdout, "--------------------------------------------------\n");}void WirelessPhy::UpdateIdleEnergy(){	if (em() == NULL) {		return;	}	if (NOW > update_energy_time_ && em()->node_on()) {		  em()-> DecrIdleEnergy(NOW-update_energy_time_,					P_idle_);		  update_energy_time_ = NOW;	}	// log node energy	if (em()->energy() > 0) {		((MobileNode *)node_)->log_energy(1);        } else {		((MobileNode *)node_)->log_energy(0);           }	idle_timer_.resched(10.0);}#ifdef MIT_uAMPSdoubleWirelessPhy::pktEnergy(double pt, double pxcvr, int nbytes){  /*    * Energy (in Joules) is power (in Watts=Joules/sec) divided by    * bandwidth (in bits/sec) multiplied by the number of bytes, times 8 bits.   */  // If data has been spread, power per DATA bit should be the same  // as if there was no spreading ==> divide transmit power  // by spreading factor.  double bits = (double) nbytes * 8;  pt /= ss_;  double j = bits * (pt + pxcvr) / bandwidth_;  return(j);}#endif

⌨️ 快捷键说明

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