40#include "underwater-mpropagation.h"
43#include <phymac-clmsg.h>
49 : TclClass(
"Module/UW/PHYSICALNOISE")
74 if (strcasecmp(argv[1],
"addSource") == 0) {
76 int id = std::atoi(argv[2]);
77 double len = std::atof(argv[3]);
78 std::string cat = argv[4];
80 dynamic_cast<Position *
>(TclObject::lookup(argv[5]));
94 }
else if (argc == 3) {
95 if (strcasecmp(argv[1],
"removeSource") == 0) {
97 int id = std::atoi(argv[2]);
118 static int mac_addr = -1;
120 ClMsgPhy2MacAddr msg;
122 mac_addr = msg.getAddr();
128 cout <<
"MAC: " << mac_addr
129 <<
": NOISE ADDED, vector size: " <<
noise_src.size() << endl;
137 [&](
Noisesource const &ns) { return ns.id == id; }),
144 static int mac_addr = -1;
146 ClMsgPhy2MacAddr msg;
148 mac_addr = msg.getAddr();
150 MSpectralMask *sm = getRxSpectralMask(p);
153 double f_c = sm->getFreq();
154 double bw = sm->getBandwidth();
159 cout << NOW <<
" MAC Addr: " << mac_addr <<
", f_c: " << f_c
160 <<
", bandwidth: " << bw <<
", sub_bandwidth: " << sub_bw
165 Position *dstPos = getPosition();
169 assert(propagation_);
171 UnderwaterMPropagation *uwmp =
172 dynamic_cast<UnderwaterMPropagation *
>(propagation_);
176 double dist = elem.pos->getDist(dstPos);
178 for (
double freq = f_c - (bw / 2); freq < f_c + (bw / 2);
182 elem.category, (freq + sub_bw / 2), speed, elem.length);
186 std::cout <<
"ERR: Undefined or wrong ship type!"
192 double gain = uwlib_AInv(dist / 1000.0,
193 uwmp->uw.practical_spreading,
194 (freq + sub_bw / 2) / 1000.0);
195 double noiseRx = noiseTx * gain * sub_bw;
202 std::cout <<
"Total: " << total <<
", db: " << 10 * log10(total)
226 double noise = UnderwaterMPhyBpsk::getNoisePower(p);
virtual bool isDestReached() const
double getSpeed() const
Method that return the actual speed.
virtual int command(int argc, const char *const *argv) override
TCL command interpreter.
int ship_stop
If enabled, the speed is set to zero when the ship reaches its destination.
virtual void removeNoiseSourcefromID(size_t id)
It removes the noise emitter corresponding to the given id.
virtual void addNoiseSource(size_t id, double len, ship_noise::ShipCategory cat, Position *pos)
It adds the noise emitter corresponding to the given id.
static constexpr const double MS_TO_KNOTS
Conversion m/s to knots.
virtual double getSpeedKnots(Position *p) const
Compute the speed of the vessel in knots.
UnderwaterPhysicalNoise()
Constructor of UnderwaterPhysicalNoise class.
std::vector< Noisesource > noise_src
Vector that stores all the vessels.
double granularity
Number of step for the integration.
virtual double vesselNoisePower(Packet *p)
It calculates the total noise power, iterating on the vessel map.
virtual double getNoisePower(Packet *p) override
Compute the noise power, considering also vessels noise if needed.
virtual int command(int, const char *const *)
TCL command interpreter.
TclObject * create(int, const char *const *)
double getNoisefromCategory(const ShipCategory &cat, double freq, double speed, double length)
Compute the sound level of a ship given the type.
static const std::unordered_map< std::string, ShipCategory > cat_dict
Dictionary of ship categories.
ShipCategory
Enum type representing the ship categories.
Struct that contains the parameters of a vessel.
UwPhysicalNoiseClass class_module_uwphysicalnoise
Definition of UwPhysicalNoise class.