samples/main-random-walk.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 02 Jul 2007 15:15:25 +0200
changeset 1556 2d5363ef077f
parent 1555 d3e9007db75b
child 1558 1f31bc245f55
permissions -rw-r--r--
make the sample code actually do something
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     3
#include "ns3/ptr.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     4
#include "ns3/position.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     5
#include "ns3/position-set-notifier.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     6
#include "ns3/random-walk-position.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     7
#include "ns3/default-value.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     8
#include "ns3/command-line.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
     9
#include "ns3/simulator.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    10
#include "ns3/nstime.h"
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    11
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    12
using namespace ns3;
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    13
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    14
static void 
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    15
CourseChange (Ptr<const Position> position)
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    16
{
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    17
  double x, y, z;
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    18
  position->Get (x, y, z);
1556
2d5363ef077f make the sample code actually do something
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1555
diff changeset
    19
  std::cout << Simulator::Now () << ", pos=" << position << ", x=" << x << ", y=" << y << ", z=" << z << std::endl;
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    20
}
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    22
int main (int argc, char *argv[])
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    23
{
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    24
  Bind ("RandomWalkMinSpeed", "2");
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    25
  Bind ("RandomWalkMaxSpeed", "3");
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    26
  Bind ("RandomWalkMode", "Time");
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
  Bind ("RandomWalkModeDistance", "20");
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
  Bind ("RandomWalkModeTime", "2s");
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
1555
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    30
  CommandLine::Parse (argc, argv);
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    31
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    32
  Ptr<PositionSetNotifier> notifier = Create<PositionSetNotifier> ();
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    33
  Ptr<RandomWalkPosition> position = Create<RandomWalkPosition> ();
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    34
  position->AddInterface (notifier);
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    35
  notifier->RegisterListener (MakeCallback (&CourseChange));
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    36
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    37
  Simulator::StopAt (Seconds (10.0));
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    38
d3e9007db75b improve sample code, make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 1554
diff changeset
    39
  Simulator::Run ();
1554
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    40
  
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    41
  return 0;
76e781c120bb rework the notification mechanism to allow its optional use with every position model
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
}