26 #include "ns3/satellite-env-variables.h"
27 #include "ns3/singleton.h"
28 #include "ns3/string.h"
42 NS_LOG_COMPONENT_DEFINE(
"SatAntennaGainPatternContainer");
49 NS_OBJECT_ENSURE_REGISTERED(SatAntennaGainPatternContainer);
54 static TypeId tid = TypeId(
"ns3::SatAntennaGainPatternContainer")
56 .AddConstructor<SatAntennaGainPatternContainer>();
63 NS_LOG_FUNCTION(
this);
69 NS_LOG_FUNCTION(
this);
71 NS_FATAL_ERROR(
"Constructor not in use");
75 std::string patternsFolder)
77 NS_LOG_FUNCTION(
this << nbSats << patternsFolder);
83 NS_LOG_INFO(
this <<
" directory for antenna patterns set to " <<
m_patternsFolder);
87 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::SatAntennaGainPatternContainer directory "
97 while ((ent = readdir(dir)) !=
nullptr)
99 std::string filename{ent->d_name};
100 std::size_t pathLength = filename.length();
104 if (filename.substr(pathLength) ==
".txt")
106 std::string num, stem = filename.substr(0, pathLength);
107 std::size_t found = stem.find_last_not_of(
numbers);
108 if (found == std::string::npos)
115 num = stem.substr(found + 1);
116 stem.erase(found + 1);
127 "SatAntennaGainPatternContainer::SatAntennaGainPatternContainer mixing "
128 "different prefix for antenna pattern names: "
129 << prefix <<
" and " << stem);
133 std::istringstream ss{num};
139 "SatAntennaGainPatternContainer::SatAntennaGainPatternContainer unable "
140 "to find beam number in "
141 << filePath <<
" file name");
144 Ptr<SatAntennaGainPattern> gainPattern =
145 CreateObject<SatAntennaGainPattern>(filePath, geoPos);
146 std::pair<std::map<uint32_t, Ptr<SatAntennaGainPattern>>::iterator,
bool> ret;
149 if (ret.second ==
false)
151 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::"
152 "SatAntennaGainPatternContainer an antenna pattern for beam "
153 << beamId <<
" already exists!");
163 const char* error = strerror(errno);
164 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::SatAntennaGainPatternContainer unable to "
172 NS_LOG_FUNCTION(
this);
178 NS_LOG_FUNCTION(
this);
183 std::ifstream* ifs =
new std::ifstream(geoPosFilename, std::ifstream::in);
187 NS_FATAL_ERROR(
"The file " << geoPosFilename <<
" is not found.");
190 double lat, lon, alt;
191 *ifs >> lat >> lon >> alt;
202 Ptr<SatAntennaGainPattern>
205 NS_LOG_FUNCTION(
this << beamId);
207 std::map<uint32_t, Ptr<SatAntennaGainPattern>>::const_iterator agp =
212 "SatAntennaGainPatternContainer::GetAntennaGainPattern - unvalid beam id: " << beamId);
218 Ptr<SatMobilityModel>
221 NS_LOG_FUNCTION(
this << satelliteId);
223 std::map<uint32_t, Ptr<SatMobilityModel>>::const_iterator mm =
228 "SatAntennaGainPatternContainer::GetAntennaGainPattern - unvalid satellite id: "
243 double bestGain(-100.0);
250 uint32_t i = entry.first;
251 double gain = entry.second->GetAntennaGain_lin(coord, mobility);
255 if (std::isnan(gain))
259 NS_LOG_WARN(
"SatAntennaGainPatternContainer::GetBestBeamId - Beam "
260 << i <<
" returned a NAN antenna gain value!");
264 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::GetBestBeamId - Beam "
265 << i <<
" returned a NAN antenna gain value!");
268 else if (gain > bestGain)
275 if (bestId == 0 && ignoreNan)
278 "SatAntennaGainPatternContainer::GetBestBeamId - did not find any good beam! The "
279 "ground station is probably too far from the satellite. Return 0 by default.");
296 return std::numeric_limits<double>::quiet_NaN();
300 return pattern->GetAntennaGain_lin(coord, mobility);
306 NS_LOG_FUNCTION(
this);
315 Ptr<SatMobilityModel> mobility)
317 NS_LOG_FUNCTION(
this << satelliteId << mobility);
328 uint32_t beamIdIterator = it->first;
329 BeamUserInfoMap_t::iterator infoIterator;
331 for (infoIterator = info.begin(); infoIterator != info.end(); infoIterator++)
333 uint32_t beamId = infoIterator->first.second;
334 if (beamId == beamIdIterator)
GeoCoordinate class is used to store and operate with geodetic coordinates.
double GetLatitude() const
Gets latitude value of coordinate.
double GetLongitude() const
Gets longitude value of coordinate.
double GetBeamGain(uint32_t satelliteId, uint32_t beamId, GeoCoordinate coord)
Get beam gain for given coordinates.
Ptr< SatAntennaGainPattern > GetAntennaGainPattern(uint32_t beamId) const
Get the antenna pattern of a specified beam id.
std::string m_patternsFolder
GeoCoordinate GetDefaultGeoPosition()
Load the default satellite position associated to these traces.
SatAntennaGainPatternContainer()
Default constructor.
uint32_t GetBestBeamId(uint32_t satelliteId, GeoCoordinate coord, bool ignoreNan)
Get the best beam id based on the antenna patterns in a specified geo coordinate.
std::map< uint32_t, Ptr< SatAntennaGainPattern > > m_antennaPatternMap
Container of antenna patterns.
uint32_t GetNAntennaGainPatterns() const
Get the number of stored antenna pattern.
void SetEnabledBeams(BeamUserInfoMap_t &info)
~SatAntennaGainPatternContainer()
static TypeId GetTypeId(void)
Get the type ID.
std::map< std::pair< uint32_t, uint32_t >, SatBeamUserInfo > BeamUserInfoMap_t
definition for beam map key is pair sat ID / beam ID and value is UT/user info.
TypeId GetInstanceTypeId() const
void ConfigureBeamsMobility(uint32_t satelliteId, Ptr< SatMobilityModel > mobility)
Ptr< SatMobilityModel > GetAntennaMobility(uint32_t satelliteId) const
Get the mobility model of a specified satellite id.
std::map< uint32_t, Ptr< SatMobilityModel > > m_mobilityModelMap
Container of mobility models.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
const std::string numbers