25 #include "ns3/double.h"
39 NS_LOG_COMPONENT_DEFINE(
"SatAntennaGainPattern");
46 NS_OBJECT_ENSURE_REGISTERED(SatAntennaGainPattern);
52 TypeId(
"ns3::SatAntennaGainPattern")
54 .AddConstructor<SatAntennaGainPattern>()
56 "MinAcceptableAntennaGainDb",
57 "Minimum acceptable antenna gain in dBs",
60 MakeDoubleChecker<double>());
73 m_minAcceptableAntennaGainInDb(40.0),
74 m_uniformRandomVariable(),
83 m_latDefaultSatellite(0.0),
84 m_lonDefaultSatellite(0.0),
92 : m_nanStrings(m_nanStringArray,
93 m_nanStringArray + (sizeof m_nanStringArray / sizeof m_nanStringArray[0]))
98 ObjectBase::ConstructSelf(AttributeConstructionList());
110 NS_LOG_FUNCTION(
this << filePathName);
113 std::ifstream* ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
119 filePathName =
"../../" + filePathName;
120 ifs =
new std::ifstream(filePathName.c_str(), std::ifstream::in);
124 NS_FATAL_ERROR(
"The file " << filePathName <<
" is not found.");
129 std::vector<double> rowVector;
132 double lat, lon, gainDouble;
133 std::string gainString;
134 bool firstRowDone(
false);
136 double bestGain = -100;
139 *ifs >> lat >> lon >> gainString;
144 if (lat < -90.0 || lat > 90.0 || lon < -180.0 || lon > 180.0)
146 NS_FATAL_ERROR(
"SatAntennaGainPattern::ReadAntennaPatternFromFile - unvalid latitude: "
147 << lat <<
" or longitude. " << lon);
159 gainDouble = atof(gainString.c_str());
198 if (gainDouble > bestGain)
200 bestGain = gainDouble;
206 if (rowVector.empty())
210 rowVector.push_back(gainDouble);
215 rowVector.push_back(gainDouble);
225 rowVector.push_back(gainDouble);
233 *ifs >> lat >> lon >> gainString;
250 Ptr<SatMobilityModel> mobility)
const
252 NS_LOG_FUNCTION(
this);
256 NS_FATAL_ERROR(
"SatAntennaGainPattern::GetSatelliteOffset - Called without initializing "
257 "satellite position first");
265 NS_LOG_DEBUG(
this <<
" Satellite offset (moved from the beginning of the simulation): "
266 << latOffset <<
" / " << lonOffset);
272 NS_LOG_FUNCTION(
this);
276 NS_FATAL_ERROR(
"SatAntennaGainPattern::GetCenterLatitude - Called without initializing "
277 "satellite position first");
289 NS_LOG_FUNCTION(
this);
293 NS_FATAL_ERROR(
"SatAntennaGainPattern::GetCenterLongitude - Called without initializing "
294 "satellite position first");
306 NS_LOG_FUNCTION(
this << mobility);
308 double satLatOffset, satLonOffset;
313 std::pair<double, double> lowerLeftCoord;
324 std::pair<double, double> testPos;
328 testPos.second = lowerLeftCoord.second;
344 testPos.first = lowerLeftCoord.first;
359 double latitude = lowerLeftCoord.first + latOffset - satLatOffset;
360 double longitude = lowerLeftCoord.second + lonOffset - satLonOffset;
369 TracedCallback<double> cb,
370 Ptr<SatMobilityModel> mobility)
const
384 double satLatOffset, satLonOffset;
388 double latitude = coord.
GetLatitude() + satLatOffset;
394 NS_LOG_WARN(
"Given latitude and longitude out of range!");
395 return std::numeric_limits<double>::quiet_NaN();
411 NS_LOG_WARN(
this <<
", some value(s) of the interpolated grid point(s) is/are NAN!");
412 return std::numeric_limits<double>::quiet_NaN();
433 double valLatLower = upperLonShare * G11 + lowerLonShare * G12;
436 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.
double m_centerLatitude
Latitude with best gain.
void GetSatelliteOffset(double &latOffset, double &lonOffset, Ptr< SatMobilityModel > mobility) const
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
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 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.
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::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.