set opt(prop) propagation/FreeSpace
Leyond wrote:
>
> Hello,all
> I want to calculate the signal strength received from some APS. But
> up to now, I just have written some codes like below to implement this
> function[of course, i am not sure it is correct or not]:-((
>
> proc record {} {
> global filepr pt l lambda gt gr pi node
> set ns [Simulator instance]
> set time 0.1;# record 0.5 second
> set m_x [$node(1) set X_]
> set m_y [$node(1) set Y_]
> set n_x [$node(0) set X_]
> set n_y [$node(0) set Y_]
> set d [expr (sqrt(pow(($m_x - $n_x),2)+ pow(($m_y-$n_y),2)))]
> set m [expr (1 /(4 * $pi * $d))]
> set pr [expr ($pt * $gr * $gt * $m * $m / 1)]
> set now [$ns now]
>
> puts $filepr "$d\t$pr"
> $ns at [expr $now + $time] "record"
> }
> I set all the parameters but d to calculate Pr. About d, I record the
> dynamic coordinate(x,y), and then compared it to the coordiate of
> AP(x1,y1) to get d.
> But now, I want to implement using a function written in the file
> /mobile/propagation.cc
>
> double FreeSpace::Pr(PacketStamp *t, PacketStamp *r, WirelessPhy *ifp)
> {
> double L = ifp->getL(); // system loss
> double lambda = ifp->getLambda(); // wavelength
>
> double Xt, Yt, Zt; // location of transmitter
> double Xr, Yr, Zr; // location of receiver
>
> t->getNode()->getLoc(&Xt, &Yt, &Zt);
> r->getNode()->getLoc(&Xr, &Yr, &Zr);
>
> // Is antenna position relative to node position?
> Xr += r->getAntenna()->getX();
> Yr += r->getAntenna()->getY();
> Zr += r->getAntenna()->getZ();
> Xt += t->getAntenna()->getX();
> Yt += t->getAntenna()->getY();
> Zt += t->getAntenna()->getZ();
>
> double dX = Xr - Xt;
> double dY = Yr - Yt;
> double dZ = Zr - Zt;
> double d = sqrt(dX * dX + dY * dY + dZ * dZ);
>
> // get antenna gain
> double Gt = t->getAntenna()->getTxGain(dX, dY, dZ, lambda);
> double Gr = r->getAntenna()->getRxGain(dX, dY, dZ, lambda);
>
> // calculate receiving power at distance
> double Pr = Friis(t->getTxPr(), Gt, Gr, lambda, L, d);
> // warning: use of `l' length character with `f' type character
> // - Sally Floyd, FreeBSD.
> printf("%lf: d: %lf, Pr: %e\n", Scheduler::instance().clock(), d, Pr);
>
> return Pr;
> }
>
> The question is I don't know how to call this c++ function using tcl
> script ?
> So, thanks very much.
> Liceven
>
>
--
View this message in context:
http://old.nabble.com/Calculate-Signal-strength-in-ns2-tp18536913p34950173.html
Sent from the ns-users mailing list archive at Nabble.com.