00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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;
00058 double Xr, Yr, Zr;
00059
00060
00061
00062
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
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
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
00094 double Pr = Friis(Pt, Gt, Gr, lambda, L, d);
00095
00096
00097
00098
00099
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