26 #include "ns3/satellite-env-variables.h"
27 #include "ns3/singleton.h"
28 #include "ns3/string.h"
36 NS_LOG_COMPONENT_DEFINE(
"SatAntennaGainPatternContainer");
43 NS_OBJECT_ENSURE_REGISTERED(SatAntennaGainPatternContainer);
49 TypeId(
"ns3::SatAntennaGainPatternContainer")
51 .AddConstructor<SatAntennaGainPatternContainer>()
54 "Sub-folder in 'antennapatterns' containing the gains definition for each beam",
55 StringValue(
"SatAntennaGain72Beams"),
64 NS_LOG_FUNCTION(
this);
70 NS_LOG_FUNCTION(
this);
72 ObjectBase::ConstructSelf(AttributeConstructionList());
74 std::string dataPath{Singleton<SatEnvVariables>::Get()->LocateDataDirectory()};
75 std::string patternsFolder = dataPath +
"/antennapatterns/" +
m_patternsFolder;
79 NS_LOG_INFO(
this <<
" directory for antenna patterns set to " << patternsFolder);
81 if (!Singleton<SatEnvVariables>::Get()->IsValidDirectory(patternsFolder))
83 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::SatAntennaGainPatternContainer directory "
90 if ((dir = opendir(patternsFolder.c_str())) !=
nullptr)
93 while ((ent = readdir(dir)) !=
nullptr)
95 std::string filename{ent->d_name};
96 std::size_t pathLength = filename.length();
100 if (filename.substr(pathLength) ==
".txt")
102 std::string num, stem = filename.substr(0, pathLength);
103 std::size_t found = stem.find_last_not_of(
numbers);
104 if (found == std::string::npos)
111 num = stem.substr(found + 1);
112 stem.erase(found + 1);
123 "SatAntennaGainPatternContainer::SatAntennaGainPatternContainer mixing "
124 "different prefix for antenna pattern names: "
125 << prefix <<
" and " << stem);
128 std::string filePath = patternsFolder +
"/" + filename;
129 std::istringstream ss{num};
135 "SatAntennaGainPatternContainer::SatAntennaGainPatternContainer unable "
136 "to find beam number in "
137 << filePath <<
" file name");
140 Ptr<SatAntennaGainPattern> gainPattern =
141 CreateObject<SatAntennaGainPattern>(filePath, geoPos);
142 std::pair<std::map<uint32_t, Ptr<SatAntennaGainPattern>>::iterator,
bool> ret;
144 if (ret.second ==
false)
146 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::"
147 "SatAntennaGainPatternContainer an antenna pattern for beam "
148 << beamId <<
" already exists!");
158 const char* error = strerror(errno);
159 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::SatAntennaGainPatternContainer unable to "
167 NS_LOG_FUNCTION(
this);
173 NS_LOG_FUNCTION(
this);
175 std::string dataPath{Singleton<SatEnvVariables>::Get()->LocateDataDirectory()};
176 std::string geoPosFilename = dataPath +
"/antennapatterns/" +
m_patternsFolder +
"/GeoPos.in";
179 std::ifstream* ifs =
new std::ifstream(geoPosFilename, std::ifstream::in);
183 NS_FATAL_ERROR(
"The file " << geoPosFilename <<
" is not found.");
186 double lat, lon, alt;
187 *ifs >> lat >> lon >> alt;
198 Ptr<SatAntennaGainPattern>
201 NS_LOG_FUNCTION(
this << beamId);
203 std::map<uint32_t, Ptr<SatAntennaGainPattern>>::const_iterator agp =
208 "SatAntennaGainPatternContainer::GetAntennaGainPattern - unvalid beam id: " << beamId);
214 Ptr<SatMobilityModel>
217 NS_LOG_FUNCTION(
this << satelliteId);
219 std::map<uint32_t, Ptr<SatMobilityModel>>::const_iterator mm =
224 "SatAntennaGainPatternContainer::GetAntennaGainPattern - unvalid satellite id: "
238 double bestGain(-100.0);
245 uint32_t i = entry.first;
246 double gain = entry.second->GetAntennaGain_lin(coord, mobility);
250 if (std::isnan(gain))
254 NS_LOG_WARN(
"SatAntennaGainPatternContainer::GetBestBeamId - Beam "
255 << i <<
" returned a NAN antenna gain value!");
259 NS_FATAL_ERROR(
"SatAntennaGainPatternContainer::GetBestBeamId - Beam "
260 << i <<
" returned a NAN antenna gain value!");
263 else if (gain > bestGain)
270 if (bestId == 0 && ignoreNan)
273 "SatAntennaGainPatternContainer::GetBestBeamId - did not find any good beam! The "
274 "ground station is probably too far from the satellite. Return 1 by default.");
284 NS_LOG_FUNCTION(
this);
293 Ptr<SatMobilityModel> mobility)
295 NS_LOG_FUNCTION(
this << satelliteId << mobility);
306 uint32_t beamIdIterator = it->first;
307 BeamUserInfoMap_t::iterator infoIterator;
309 for (infoIterator = info.begin(); infoIterator != info.end(); infoIterator++)
311 uint32_t beamId = infoIterator->first.second;
312 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.
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.
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 beam id.
SatAntennaGainPatternContainer(uint32_t nbSats=1)
Default constructor.
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