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
00032
00033
00034
00035
00036
00037
00038 #include <math.h>
00039
00040 #include <delay.h>
00041 #include <packet.h>
00042 #include <node-core.h>
00043
00044 #include <packet-stamp.h>
00045 #include <antenna.h>
00046 #include <mobilenode.h>
00047 #include <mrcl_propagation.h>
00048 #include <mrcl_wireless-phy.h>
00049 #include <mrcl_tworayground.h>
00050 #include "wirelessphy-module.h"
00051
00052
00053 static class MrclTwoRayGroundClass: public TclClass {
00054 public:
00055 MrclTwoRayGroundClass() : TclClass("Propagation/MrclTwoRayGround") {}
00056 TclObject* create(int, const char*const*) {
00057 return (new MrclTwoRayGround);
00058 }
00059 } class_tworayground;
00060
00061 MrclTwoRayGround::MrclTwoRayGround()
00062 {
00063 last_hr = last_ht = 0.0;
00064 crossover_dist = 0.0;
00065 }
00066
00067
00068
00069
00070 double MrclTwoRayGround::TwoRay(double Pt, double Gt, double Gr, double ht, double hr, double L, double d)
00071 {
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 return Pt * Gt * Gr * (hr * hr * ht * ht) / (d * d * d * d * L);
00083 }
00084
00085 double
00086 MrclTwoRayGround::Pr(Packet *p, PacketStamp *t, PacketStamp *r, double L, double lambda)
00087 {
00088 Position *sourcePos;
00089 Position *destPos;
00090 double rX, rY, rZ;
00091 double tX, tY, tZ;
00092 double d;
00093 double hr, ht;
00094 double Pr;
00095
00096
00097
00098
00099
00100
00101
00102 hdr_MrclWrlPhy *wph = HDR_MRCLWRLPHY(p);
00103 sourcePos = wph->sourcePos_;
00104 destPos = wph->destPos_;
00105
00106 rX = destPos->getX();
00107 rY = destPos->getY();
00108 rZ = 0.;
00109 tX = sourcePos->getX();
00110 tY = sourcePos->getY();
00111 tZ = 0.;
00112
00113 rX += r->getAntenna()->getX();
00114 rY += r->getAntenna()->getY();
00115 tX += t->getAntenna()->getX();
00116 tY += t->getAntenna()->getY();
00117
00118 d = sqrt((rX - tX) * (rX - tX)
00119 + (rY - tY) * (rY - tY)
00120 + (rZ - tZ) * (rZ - tZ));
00121
00122
00123
00124
00125
00126
00127
00128 if (rZ != tZ) {
00129 printf("%s: MrclTwoRayGround propagation model assume flat ground\n",
00130 __FILE__);
00131 }
00132
00133 hr = rZ + r->getAntenna()->getZ();
00134 ht = tZ + t->getAntenna()->getZ();
00135
00136 if (hr != last_hr || ht != last_ht)
00137 {
00138
00139
00140
00141
00142
00143
00144
00145
00146 crossover_dist = (4 * PI * ht * hr) / lambda;
00147 last_hr = hr; last_ht = ht;
00148 #if DEBUG > 3
00149 printf("TRG: xover %e.10 hr %f ht %f\n",
00150 crossover_dist, hr, ht);
00151 #endif
00152 }
00153
00154
00155
00156
00157
00158
00159
00160 double Gt = t->getAntenna()->getTxGain(rX - tX, rY - tY, rZ - tZ,
00161 t->getLambda());
00162 double Gr = r->getAntenna()->getRxGain(tX - rX, tY - rY, tZ - rZ,
00163 r->getLambda());
00164
00165 #if DEBUG > 5
00166 printf("TRG %.9f %d(%d,%d)@%d(%d,%d) d=%f xo=%f :",
00167 Scheduler::instance().clock(),
00168 t->getNode()->index(), (int)tX, (int)tY,
00169 r->getNode()->index(), (int)rX, (int)rY,
00170 d, crossover_dist);
00171
00172
00173 #endif
00174
00175 if(d <= crossover_dist) {
00176 Pr = Friis(t->getTxPr(), Gt, Gr, lambda, L, d);
00177 #if DEBUG > 3
00178 printf("Friis %e\n",Pr);
00179 #endif
00180 return Pr;
00181 }
00182 else {
00183 Pr = TwoRay(t->getTxPr(), Gt, Gr, ht, hr, L, d);
00184 #if DEBUG > 3
00185 printf("TwoRay %e\n",Pr);
00186 #endif
00187 return Pr;
00188 }
00189 }
00190
00191 double MrclTwoRayGround::getDist(double Pr, double Pt, double Gt, double Gr, double hr, double ht, double L, double lambda)
00192 {
00193
00194 return sqrt(sqrt(Pt * Gt * Gr * (hr * hr * ht * ht) / Pr));
00195 }