--- a/src/node/ns2-mobility-file-topology.cc Thu Jul 19 10:05:07 2007 +0200
+++ b/src/node/ns2-mobility-file-topology.cc Thu Jul 19 10:17:02 2007 +0200
@@ -129,7 +129,7 @@
double zSpeed = ReadDouble (line.substr (ySpeedEnd + 1, std::string::npos));
NS_DEBUG ("at=" << at << "xSpeed=" << xSpeed << ", ySpeed=" << ySpeed << ", zSpeed=" << zSpeed);
Simulator::Schedule (Seconds (at), &StaticSpeedMobilityModel::SetSpeed, model,
- xSpeed, ySpeed, zSpeed);
+ Speed (xSpeed, ySpeed, zSpeed));
}
}
file.close();
--- a/src/node/static-speed-helper.cc Thu Jul 19 10:05:07 2007 +0200
+++ b/src/node/static-speed-helper.cc Thu Jul 19 10:17:02 2007 +0200
@@ -6,12 +6,21 @@
StaticSpeedHelper::StaticSpeedHelper ()
{}
+StaticSpeedHelper::StaticSpeedHelper (const Position &position)
+ : m_position (position)
+{}
+StaticSpeedHelper::StaticSpeedHelper (const Position &position,
+ const Speed &speed)
+ : m_position (position),
+ m_speed (speed)
+{}
void
StaticSpeedHelper::InitializePosition (const Position &position)
{
m_position = position;
m_speed.dx = 0.0;
m_speed.dy = 0.0;
+ m_speed.dz = 0.0;
m_lastUpdate = Simulator::Now ();
m_pauseEnd = Simulator::Now ();
}
@@ -35,6 +44,12 @@
{
return m_speed;
}
+void
+StaticSpeedHelper::SetSpeed (const Speed &speed)
+{
+ Update ();
+ m_speed = speed;
+}
void
StaticSpeedHelper::Update (void) const
--- a/src/node/static-speed-helper.h Thu Jul 19 10:05:07 2007 +0200
+++ b/src/node/static-speed-helper.h Thu Jul 19 10:17:02 2007 +0200
@@ -13,6 +13,9 @@
{
public:
StaticSpeedHelper ();
+ StaticSpeedHelper (const Position &position);
+ StaticSpeedHelper (const Position &position,
+ const Speed &speed);
void InitializePosition (const Position &position);
void Reset (const Speed &speed, const Time &pauseDelay);
@@ -20,6 +23,7 @@
Position GetCurrentPosition (const Rectangle &bounds) const;
Position GetCurrentPosition (void) const;
Speed GetSpeed (void) const;
+ void SetSpeed (const Speed &speed);
private:
void Update (void) const;
--- a/src/node/static-speed-mobility-model.cc Thu Jul 19 10:05:07 2007 +0200
+++ b/src/node/static-speed-mobility-model.cc Thu Jul 19 10:17:02 2007 +0200
@@ -23,54 +23,25 @@
namespace ns3 {
-const InterfaceId StaticSpeedMobilityModel::iid = MakeInterfaceId ("StaticSpeedMobilityModel", MobilityModel::iid);
+const InterfaceId StaticSpeedMobilityModel::iid =
+ MakeInterfaceId ("StaticSpeedMobilityModel", MobilityModel::iid);
const ClassId StaticSpeedMobilityModel::cid =
- MakeClassId<StaticSpeedMobilityModel,double, double> ("StaticSpeedMobilityModel",
- StaticSpeedMobilityModel::iid);
+ MakeClassId<StaticSpeedMobilityModel> ("StaticSpeedMobilityModel",
+ StaticSpeedMobilityModel::iid);
StaticSpeedMobilityModel::StaticSpeedMobilityModel ()
- : m_x (0.0),
- m_y (0.0),
- m_z (0.0),
- m_dx (0.0),
- m_dy (0.0),
- m_dz (0.0),
- m_prevTime (Simulator::Now ())
{
SetInterfaceId (StaticSpeedMobilityModel::iid);
}
-StaticSpeedMobilityModel::StaticSpeedMobilityModel (double x, double y, double z)
- : m_x (x),
- m_y (y),
- m_z (z),
- m_dx (0.0),
- m_dy (0.0),
- m_dz (0.0),
- m_prevTime (Simulator::Now ())
+StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Position &position)
+ : m_helper (position)
{
SetInterfaceId (StaticSpeedMobilityModel::iid);
}
-StaticSpeedMobilityModel::StaticSpeedMobilityModel (double x, double y)
- : m_x (x),
- m_y (y),
- m_z (0.0),
- m_dx (0.0),
- m_dy (0.0),
- m_dz (0.0),
- m_prevTime (Simulator::Now ())
-{
- SetInterfaceId (StaticSpeedMobilityModel::iid);
-}
-StaticSpeedMobilityModel::StaticSpeedMobilityModel (double x, double y, double z,
- double dx, double dy, double dz)
- : m_x (x),
- m_y (y),
- m_z (z),
- m_dx (dx),
- m_dy (dy),
- m_dz (dz),
- m_prevTime (Simulator::Now ())
+StaticSpeedMobilityModel::StaticSpeedMobilityModel (const Position &position,
+ const Speed &speed)
+ : m_helper (position, speed)
{
SetInterfaceId (StaticSpeedMobilityModel::iid);
}
@@ -79,56 +50,23 @@
{}
void
-StaticSpeedMobilityModel::SetSpeed (double dx, double dy, double dz)
+StaticSpeedMobilityModel::SetSpeed (const Speed speed)
{
- bool changed = false;
- Update ();
- if (m_dx != dx || m_dy != dy || m_dz != dz)
- {
- changed = true;
- }
- m_dx = dx;
- m_dy = dy;
- m_dz = dz;
- if (changed)
- {
- NotifyCourseChange ();
- }
+ m_helper.SetSpeed (speed);
+ NotifyCourseChange ();
}
-void
-StaticSpeedMobilityModel::Update (void) const
-{
- Time deltaTime = Simulator::Now () - m_prevTime;
- m_prevTime = Simulator::Now ();
- double deltaS = deltaTime.GetSeconds ();
- m_x += m_dx * deltaS;
- m_y += m_dy * deltaS;
- m_z += m_dz * deltaS;
-}
Position
StaticSpeedMobilityModel::DoGet (void) const
{
- Update ();
- return Position (m_x, m_y, m_z);
+ return m_helper.GetCurrentPosition ();
}
void
StaticSpeedMobilityModel::DoSet (const Position &position)
{
- bool changed = false;
- Update ();
- if (m_x != position.x || m_y != position.y || m_z != position.z)
- {
- changed = true;
- }
- m_x = position.x;
- m_y = position.y;
- m_z = position.z;
- if (changed)
- {
- NotifyCourseChange ();
- }
+ m_helper.InitializePosition (position);
+ NotifyCourseChange ();
}
}; // namespace ns3
--- a/src/node/static-speed-mobility-model.h Thu Jul 19 10:05:07 2007 +0200
+++ b/src/node/static-speed-mobility-model.h Thu Jul 19 10:17:02 2007 +0200
@@ -25,6 +25,8 @@
#include "mobility-model.h"
#include "ns3/nstime.h"
#include "ns3/component-manager.h"
+#include "static-speed-helper.h"
+#include "speed.h"
namespace ns3 {
@@ -39,60 +41,31 @@
*/
StaticSpeedMobilityModel ();
/**
- * \param x x coordinate
- * \param y y coordinate
- *
- * Create a position located at coordinates (x,y,0) with
- * speed (0,0,0).
- * Unit is meters
- */
- StaticSpeedMobilityModel (double x, double y);
- /**
- * \param x x coordinate
- * \param y y coordinate
- * \param z z coordinate
- *
* Create a position located at coordinates (x,y,z) with
* speed (0,0,0).
- * Unit is meters
*/
- StaticSpeedMobilityModel (double x, double y, double z);
+ StaticSpeedMobilityModel (const Position &position);
/**
- * \param x x coordinate
- * \param y y coordinate
- * \param z z coordinate
- * \param dx x coordinate speed
- * \param dy y coordinate speed
- * \param dz z coordinate speed
*
* Create a position located at coordinates (x,y,z) with
* speed (dx,dy,dz).
* Unit is meters and meters/s
*/
- StaticSpeedMobilityModel (double x, double y, double z,
- double dx, double dy, double dz);
+ StaticSpeedMobilityModel (const Position &position,
+ const Speed &speed);
virtual ~StaticSpeedMobilityModel ();
/*
- * \param dx x coordinate speed
- * \param dy y coordinate speed
- * \param dz z coordinate speed
*
* Set the current speed now to (dx,dy,dz)
* Unit is meters/s
*/
- void SetSpeed (double dx, double dy, double dz);
+ void SetSpeed (const Speed speed);
private:
virtual Position DoGet (void) const;
virtual void DoSet (const Position &position);
void Update (void) const;
- mutable double m_x;
- mutable double m_y;
- mutable double m_z;
- double m_dx;
- double m_dy;
- double m_dz;
- mutable Time m_prevTime;
+ StaticSpeedHelper m_helper;
};
}; // namespace ns3