do a binary search for the range boundary.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue, 10 Jun 2008 16:22:21 -0700
changeset 3883 091bb8fef41f
parent 3882 05de3d432860
child 3884 260d8acdbd01
do a binary search for the range boundary.
src/devices/wifi/wifi-phy-test.cc
--- a/src/devices/wifi/wifi-phy-test.cc	Tue Jun 10 16:22:12 2008 -0700
+++ b/src/devices/wifi/wifi-phy-test.cc	Tue Jun 10 16:22:21 2008 -0700
@@ -188,27 +188,37 @@
 
 static void PrintSizeVsRange (int argc, char *argv[])
 {
+  double minPsr = 0.05;
   struct PsrExperiment::Input input = PsrExperiment::GetDefaultInput ();
   CommandLine cmd;
   cmd.AddValue ("TxPowerLevel", "The power level index to use to send each packet", input.txPowerLevel);  
   cmd.AddValue ("TxMode", "The mode to use to send each packet", input.txMode);
   cmd.AddValue ("NPackets", "The number of packets to send", input.nPackets);
+  cmd.AddValue ("LowPsr", "The minimum psr needed to assume that we are within range", minPsr);
   cmd.Parse (argc, argv);
   for (input.packetSize = 10; input.packetSize < 3000; input.packetSize += 40)
     {
-      for (input.distance = 100.0; input.distance < 170; input.distance += 2.0)
+      double precision = 0.1;
+      double low = 1.0;
+      double high = 200.0;
+      while (high - low > precision)
 	{
+	  double middle = low + (high - low) / 2;
 	  struct PsrExperiment::Output output;
 	  PsrExperiment experiment;
+	  input.distance = middle;
 	  output = experiment.Run (input);
-	  double psr = output.received;
-	  psr /= input.nPackets ;
-	  if (psr <= 0.05)
+	  double psr = CalcPsr (output, input);
+	  if (psr >= minPsr)
 	    {
-	      std::cout << input.packetSize << " " << input.distance << std::endl;
-	      break;
+	      low = middle;
+	    }
+	  else
+	    {
+	      high = middle;
 	    }
 	}
+      std::cout << input.packetSize << " " << input.distance << std::endl;
     }
 }