mrcl_freespace.cc

00001 /*
00002  * Copyright (c) 2007 Regents of the SIGNET lab, University of Padova.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the University of Padova (SIGNET lab) nor the 
00014  *    names of its contributors may be used to endorse or promote products 
00015  *    derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00018  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 
00019  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
00020  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
00021  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
00022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
00023  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
00024  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
00025  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
00026  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
00027  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 /* -*-  Mode:C++ -*- */
00031 #include "mrcl_freespace.h"
00032 
00033 #include <node-core.h>
00034 #include <stdio.h>
00035 
00036 
00037 #include "mrcl_wireless-phy.h"
00038 #include "wirelessphy-module.h"
00039 
00040 
00041 class PacketStamp;
00042 
00043 static class MrclFreeSpaceClass: public TclClass {
00044 public:
00045         MrclFreeSpaceClass() : TclClass("Propagation/MrclFreeSpace") {}
00046         TclObject* create(int, const char*const*) {
00047                 return (new MrclFreeSpace);
00048         }                   
00049 } class_mrclfreespace;
00050 
00051 
00052 double MrclFreeSpace::Pr(Packet *p, PacketStamp *t, PacketStamp *r, double L, double lambda)
00053 {
00054         Position *sourcePos;
00055   Position *destPos;
00056 
00057         double Xt, Yt, Zt;              // location of transmitter
00058         double Xr, Yr, Zr;              // location of receiver
00059 
00060         // old position paramters (from MobileNode)
00061 //      t->getNode()->getLoc(&Xt, &Yt, &Zt);
00062 //      r->getNode()->getLoc(&Xr, &Yr, &Zr);
00063         hdr_MrclWrlPhy *wph = HDR_MRCLWRLPHY(p);
00064         sourcePos = wph->sourcePos_;
00065         destPos = wph->destPos_;
00066   
00067 
00068   Xr = destPos->getX();
00069   Yr = destPos->getY();
00070   Zr = 0.;
00071   Xt = sourcePos->getX();
00072   Yt = sourcePos->getY();
00073   Zt = 0.;
00074         // Is antenna position relative to node position?
00075         Xr += r->getAntenna()->getX();
00076         Yr += r->getAntenna()->getY();
00077         Zr += r->getAntenna()->getZ();
00078         Xt += t->getAntenna()->getX();
00079         Yt += t->getAntenna()->getY();
00080         Zt += t->getAntenna()->getZ();
00081 
00082         double dX = Xr - Xt;
00083         double dY = Yr - Yt;
00084         double dZ = Zr - Zt;
00085         double d = sqrt(dX * dX + dY * dY + dZ * dZ);
00086 
00087         // get antenna gain
00088         double Gt = t->getAntenna()->getTxGain(dX, dY, dZ, lambda);
00089         double Gr = r->getAntenna()->getRxGain(dX, dY, dZ, lambda);
00090 
00091         double Pt = t->getTxPr();
00092 
00093         // calculate receiving power at distance
00094         double Pr = Friis(Pt, Gt, Gr, lambda, L, d);
00095                                 
00096         //printf("%lf: d: %lf, Pr: %e\n", Scheduler::instance().clock(), d, Pr);
00097 
00098         // This is a Free Space model, which is valid only in the far field.
00099         // This part prevents Pr to be > Pt for d close to 0
00100         if (Pr<Pt)
00101                 return Pr;
00102         else
00103                 return Pt;
00104 }
00105 
00106 double MrclFreeSpace::getDist(double Pr, double Pt, double Gt, double Gr, double hr, double ht, double L, double lambda)
00107 {
00108         return sqrt((Pt * Gt * Gr * lambda * lambda) / (L * Pr)) /
00109                 (4 * PI);
00110 }
00111 

Generated on Wed Nov 26 15:47:28 2008 for NS-MIRACLE library by  doxygen 1.5.2