satellite-mobility-model.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Sami Rantanen <sami.rantanen@magister.fi>
19  */
20 
22 
23 #include <ns3/boolean.h>
24 #include <ns3/log.h>
25 #include <ns3/trace-source-accessor.h>
26 
27 #include <cmath>
28 #include <stdint.h>
29 
30 namespace ns3
31 {
32 
33 NS_OBJECT_ENSURE_REGISTERED(SatMobilityModel);
34 
35 TypeId
37 {
38  static TypeId tid =
39  TypeId("ns3::SatMobilityModel")
40  .SetParent<MobilityModel>()
41  .AddAttribute("SatPosition",
42  "The current position of the mobility model.",
43  TypeId::ATTR_SET | TypeId::ATTR_GET,
44  GeoCoordinateValue(GeoCoordinate(0.0, 0.0, 0.0)),
45  MakeGeoCoordinateAccessor(&SatMobilityModel::SetGeoPosition,
48  .AddAttribute("AsGeoCoordinates",
49  "SetPosition method takes Geodetic coordinates in given Vector, "
50  "x=longitude, y=latitude, z=altitude",
51  BooleanValue(true),
52  MakeBooleanAccessor(&SatMobilityModel::m_GetAsGeoCoordinates),
53  MakeBooleanChecker())
54  .AddTraceSource("SatCourseChange",
55  "The value of the position and/or velocity coordinate changed",
56  MakeTraceSourceAccessor(&SatMobilityModel::m_satCourseChangeTrace),
57  "ns3::SatMobilityModel::CourseChangeCallback");
58  return tid;
59 }
60 
61 TypeId
63 {
64  return GetTypeId();
65 }
66 
68  : m_cartesianPositionOutdated(false),
69  m_GetAsGeoCoordinates(true)
70 {
71 }
72 
74 {
75 }
76 
79 {
80  return DoGetGeoPosition();
81 }
82 
83 void
85 {
87  DoSetGeoPosition(position);
88 }
89 
90 double
91 SatMobilityModel::GetDistanceFrom(Ptr<const SatMobilityModel> other) const
92 {
93  Vector oPosition = other->DoGetGeoPosition().ToVector();
94  Vector position = DoGetGeoPosition().ToVector();
95  return CalculateDistance(position, oPosition);
96 }
97 
98 void
100 {
102  NotifyCourseChange();
103 }
104 
105 Vector
107 {
109  {
110  Vector position = DoGetGeoPosition().ToVector();
111  DoSetCartesianPosition(position);
112  }
113 
114  return m_cartesianPosition;
115 }
116 
117 void
118 SatMobilityModel::DoSetPosition(const Vector& position)
119 {
121  {
123  DoSetGeoPosition(GeoCoordinate(position.x, position.y, position.z));
124  }
125  else
126  {
128  m_cartesianPosition = position;
129  DoSetGeoPosition(GeoCoordinate(position));
130  }
131 }
132 
133 void
134 SatMobilityModel::DoSetCartesianPosition(const Vector& position) const
135 {
137  m_cartesianPosition = position;
138 }
139 
140 } // namespace ns3
GeoCoordinate class is used to store and operate with geodetic coordinates.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
hold objects of type ns3::GeoCoordinate
virtual ~SatMobilityModel()=0
Destructor for SatMobilityModel.
TypeId GetInstanceTypeId(void) const
virtual GeoCoordinate DoGetGeoPosition(void) const =0
static TypeId GetTypeId(void)
Get the type ID.
virtual void DoSetGeoPosition(const GeoCoordinate &position)=0
void DoSetCartesianPosition(const Vector &position) const
This method is used to force update of cartesian position.
double GetDistanceFrom(Ptr< const SatMobilityModel > position) const
virtual Vector DoGetPosition(void) const
SatMobilityModel()
Default constructor.
GeoCoordinate GetGeoPosition(void) const
virtual void DoSetPosition(const Vector &position)
ns3::TracedCallback< Ptr< const SatMobilityModel > > m_satCourseChangeTrace
Used to alert subscribers that a change in direction, velocity, or position has occurred.
void SetGeoPosition(const GeoCoordinate &position)
void NotifyGeoCourseChange(void) const
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Ptr< const AttributeChecker > MakeGeoCoordinateChecker(void)