25#include "ns3/double.h"
39NS_LOG_COMPONENT_DEFINE(
"SatAntennaGainPattern");
52 TypeId(
"ns3::SatAntennaGainPattern")
54 .AddConstructor<SatAntennaGainPattern>()
56 "MinAcceptableAntennaGainDb",
57 "Minimum acceptable antenna gain in dBs",
60 MakeDoubleChecker<double>());
81 NS_FATAL_ERROR(
"Default constructor not in use");
91 NS_LOG_FUNCTION(
this << filePathName << defaultSatellitePosition);
97 NS_LOG_FUNCTION(
this);
99 Object::NotifyConstructionCompleted();
111 NS_LOG_FUNCTION(
this << filePathName);
114 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
120 filePathName =
"../../" + filePathName;
121 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
125 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
130 std::vector<double> rowVector;
133 double lat, lon, gainDouble;
134 std::string gainString;
135 bool firstRowDone(
false);
137 double bestGain = -100;
140 *ifs >> lat >> lon >> gainString;
145 if (lat < -90.0 || lat > 90.0 || lon < -180.0 || lon > 180.0)
147 NS_FATAL_ERROR(
"SatAntennaGainPattern::ReadAntennaPatternFromFile - unvalid latitude: "
148 << lat <<
" or longitude. " << lon);
160 gainDouble = atof(gainString.c_str());
199 if (gainDouble > bestGain)
201 bestGain = gainDouble;
207 if (rowVector.empty())
211 rowVector.push_back(gainDouble);
216 rowVector.push_back(gainDouble);
226 rowVector.push_back(gainDouble);
234 *ifs >> lat >> lon >> gainString;
251 Ptr<SatMobilityModel> mobility)
const
253 NS_LOG_FUNCTION(
this);
257 NS_FATAL_ERROR(
"SatAntennaGainPattern::GetSatelliteOffset - Called without initializing "
258 "satellite position first");
266 NS_LOG_DEBUG(
this <<
" Satellite offset (moved from the beginning of the simulation): "
267 << latOffset <<
" / " << lonOffset);
273 NS_LOG_FUNCTION(
this);
277 NS_FATAL_ERROR(
"SatAntennaGainPattern::GetCenterLatitude - Called without initializing "
278 "satellite position first");
290 NS_LOG_FUNCTION(
this);
294 NS_FATAL_ERROR(
"SatAntennaGainPattern::GetCenterLongitude - Called without initializing "
295 "satellite position first");
307 NS_LOG_FUNCTION(
this << mobility);
309 double satLatOffset, satLonOffset;
314 std::pair<double, double> lowerLeftCoord;
325 std::pair<double, double> testPos;
329 testPos.second = lowerLeftCoord.second;
345 testPos.first = lowerLeftCoord.first;
360 double latitude = lowerLeftCoord.first + latOffset - satLatOffset;
361 double longitude = lowerLeftCoord.second + lonOffset - satLonOffset;
370 TracedCallback<double> cb,
371 Ptr<SatMobilityModel> mobility)
const
385 double satLatOffset, satLonOffset;
389 double latitude = coord.
GetLatitude() + satLatOffset;
395 NS_LOG_WARN(
"Given latitude and longitude out of range!");
396 return std::numeric_limits<double>::quiet_NaN();
412 NS_LOG_WARN(
this <<
", some value(s) of the interpolated grid point(s) is/are NAN!");
413 return std::numeric_limits<double>::quiet_NaN();
434 double valLatLower = upperLonShare * G11 + lowerLonShare * G12;
437 double valLatUpper = upperLonShare * G21 + lowerLonShare * G22;
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.
SatAntennaGainPattern class holds the antenna gain pattern data for a one single spot-beam.
double m_centerLatitude
Latitude with best gain.
void GetSatelliteOffset(double &latOffset, double &lonOffset, Ptr< SatMobilityModel > mobility) const
double GetCenterLongitude(Ptr< SatMobilityModel > mobility) const
Get latitude of this beam with best gain, based on satellite given in mobility model.
SatAntennaGainPattern()
Default constructor.
double GetAntennaGain_lin(GeoCoordinate coord, Ptr< SatMobilityModel > mobility) const
Calculate the antenna gain value for a certain {latitude, longitude} point.
Ptr< UniformRandomVariable > m_uniformRandomVariable
Uniform random variable used for beam selection.
GeoCoordinate m_defaultSatellitePosition
GeoCoordinate GetValidRandomPosition(Ptr< SatMobilityModel > mobility) const
Get a valid random position under this spot-beam coverage.
double m_lonInterval
Interval between longitudes, must be constant.
static const std::string m_nanStringArray[4]
Valid Not-a-Number (NaN) strings.
double m_centerLongitude
Longitude with best gain.
double m_minLon
Minimum longitude value of the antenna gain pattern.
std::vector< double > m_latitudes
All valid latitudes from the file.
double m_maxLat
Maximum latitude value of the antenna gain pattern.
virtual void NotifyConstructionCompleted() override
Notifier called once the ObjectBase is fully constructed.
double m_lonDefaultSatellite
Longitude of default satellite for antenna gain pattern.
bool IsValidPosition(GeoCoordinate coord, TracedCallback< double > cb, Ptr< SatMobilityModel > mobility) const
Check if a given position is under this spot-beam coverage.
double GetCenterLatitude(Ptr< SatMobilityModel > mobility) const
Get latitude of this beam with best gain, based on satellite given in mobility model.
double m_minAcceptableAntennaGainInDb
Minimum acceptable antenna gain for a serving spot-beam.
std::string m_filePathName
std::vector< std::string > m_nanStrings
double m_latDefaultSatellite
Latitude of default satellite for antenna gain pattern.
double m_maxLon
Minimum longitude value of the antenna gain pattern.
double m_minLat
Minimum latitude value of the antenna gain pattern.
void ReadAntennaPatternFromFile(std::string filePathName)
Read the antenna gain pattern from a file.
std::vector< std::pair< double, double > > m_validPositions
Container for valid positions.
std::vector< double > m_longitudes
All valid latitudes from the file.
std::vector< std::vector< double > > m_antennaPattern
Container for the antenna pattern from one spot-beam.
static TypeId GetTypeId(void)
Get the type ID.
double m_latInterval
Interval between latitudes, must be constant.
static T DbToLinear(T db)
Converts decibels to linear.
static T LinearToDb(T linear)
Converts linear to decibels.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.