satellite-traced-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) 2018 CNES
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: Mathias Ettinger <mettinger@toulouse.viveris.com>
19  */
20 
22 
24 
25 #include <ns3/enum.h>
26 #include <ns3/log.h>
27 #include <ns3/simulator.h>
28 #include <ns3/singleton.h>
29 
30 #include <string>
31 
32 NS_LOG_COMPONENT_DEFINE("SatTracedMobilityModel");
33 
34 namespace ns3
35 {
36 
37 NS_OBJECT_ENSURE_REGISTERED(SatTracedMobilityModel);
38 
39 TypeId
41 {
42  static TypeId tid =
43  TypeId("ns3::SatTracedMobilityModel")
44  .SetParent<SatMobilityModel>()
45  .AddConstructor<SatTracedMobilityModel>()
46  .AddAttribute("ReferenceEllipsoid",
47  "Reference Ellipsoid model to use when reading coordinates",
48  EnumValue(GeoCoordinate::SPHERE),
49  MakeEnumAccessor<GeoCoordinate::ReferenceEllipsoid_t>(
51  MakeEnumChecker(GeoCoordinate::SPHERE,
52  "Sphere",
54  "WGS84",
56  "GRS80"))
57  .AddAttribute("UpdateInterval",
58  "Interval at which the position should update",
59  TimeValue(MilliSeconds(1)),
61  MakeTimeChecker(FemtoSeconds(1)));
62 
63  return tid;
64 }
65 
66 TypeId
68 {
69  return GetTypeId();
70 }
71 
72 void
74 {
75  m_antennaGainPatterns = nullptr;
76 
77  Object::DoDispose();
78 }
79 
81 {
82  NS_FATAL_ERROR("SatTracedMobilityModel default constructor should not be used");
83 }
84 
86  const std::string& filename,
87  Ptr<SatAntennaGainPatternContainer> agp)
88  : m_satId(satId),
89  m_traceFilename(filename),
90  m_updateInterval(MilliSeconds(1)),
91  m_refEllipsoid(GeoCoordinate::SPHERE),
92  m_geoPosition(0.0, 0.0, 0.0),
93  m_velocity(0.0, 0.0, 0.0),
94  m_antennaGainPatterns(agp)
95 {
96  NS_LOG_FUNCTION(this);
97 
99 }
100 
102 {
103  NS_LOG_FUNCTION(this);
104 }
105 
108 {
109  NS_LOG_FUNCTION(this);
110 
111  return m_geoPosition;
112 }
113 
114 void
116 {
117  NS_LOG_FUNCTION(this << position);
118 
119  double time = m_updateInterval.GetSeconds();
120  Vector distance = position.ToVector() - m_geoPosition.ToVector();
121  m_velocity = Vector(distance.x / time, distance.y / time, distance.z / time);
122 
123  NS_LOG_INFO("Changing position from " << m_geoPosition << " to " << position << ". Velocity is "
124  << m_velocity << " (" << m_velocity.GetLength() << ")");
125 
126  m_geoPosition = position;
128 }
129 
130 Vector
132 {
133  NS_LOG_FUNCTION(this);
134 
135  return m_velocity;
136 }
137 
138 void
140 {
141  NS_LOG_FUNCTION(this);
142 
143  GeoCoordinate newPosition =
144  Singleton<SatPositionInputTraceContainer>::Get()->GetPosition(m_traceFilename,
146  DoSetGeoPosition(newPosition);
147 
149 }
150 
151 void
153 {
154  m_satId = satId;
155 }
156 
157 uint32_t
159 {
160  return m_satId;
161 }
162 
163 uint32_t
165 {
166  return m_antennaGainPatterns->GetBestBeamId(m_satId, m_geoPosition, ignoreNan);
167 }
168 
169 } // namespace ns3
GeoCoordinate class is used to store and operate with geodetic coordinates.
Vector ToVector() const
Converts Geodetic coordinates to Cartesian coordinates.
Keep track of the current position and velocity of an object in satellite network.
void NotifyGeoCourseChange(void) const
void SetSatId(uint32_t satId)
Set the satellite ID linked to this node.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t GetBestBeamId(bool ignoreNan=false) const
Return the best beam ID based on the current position.
Ptr< SatAntennaGainPatternContainer > m_antennaGainPatterns
virtual ~SatTracedMobilityModel()
Destructor for SatMobilityModel.
uint32_t GetSatId(void) const
Return the satellite ID linked to this node.
virtual void DoDispose()
Dispose of this class instance.
virtual GeoCoordinate DoGetGeoPosition(void) const
virtual void DoSetGeoPosition(const GeoCoordinate &position)
GeoCoordinate::ReferenceEllipsoid_t m_refEllipsoid
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.