43const double K = 1.38 * 1.E-23;
44const double q = 1.6 * 1.E-19;
50 : TclClass(
"Module/UW/UWOPTICALBEAMPATTERN")
63 beam_pattern_path_tx_(
""),
64 beam_pattern_path_rx_(
""),
66 beam_pattern_separator_(
','),
67 max_dist_separator_(
','),
71 back_noise_threshold_(0),
72 inclination_angle_(0),
84 if (strcasecmp(argv[1],
"useSameBeamPattern") == 0) {
87 }
else if (strcasecmp(argv[1],
"useDifferentBeamPattern") == 0) {
92 }
else if (argc == 3) {
93 if (strcasecmp(argv[1],
"setBeamPatternPath") == 0) {
95 fprintf(stderr,
"sameBeam set as false, 2 beam pattern paths needed");
98 string tmp_ = ((
char *) argv[2]);
99 if (tmp_.size() == 0) {
100 fprintf(stderr,
"Empty string for the file name");
103 std::cout <<
"Use same beam pattern for tx and rx" << std::endl;
107 }
else if (strcasecmp(argv[1],
"setMaxRangePath") == 0) {
108 string tmp_ = ((
char *) argv[2]);
109 if (tmp_.size() == 0) {
110 fprintf(stderr,
"Empty string for the file name");
115 }
else if (strcasecmp(argv[1],
"setBeamSeparator") == 0) {
116 string tmp_ = ((
char *) argv[2]);
117 if (tmp_.size() == 0) {
118 fprintf(stderr,
"Empty char for the file name");
123 }
else if (strcasecmp(argv[1],
"setMaxRangeSeparator") == 0) {
124 string tmp_ = ((
char *) argv[2]);
125 if (tmp_.size() == 0) {
126 fprintf(stderr,
"Empty char for the file name");
131 }
else if (strcasecmp(argv[1],
"setInclinationAngle") == 0) {
136 }
else if (argc == 4) {
137 if (strcasecmp(argv[1],
"setBeamPatternPath") == 0) {
139 fprintf(stderr,
"sameBeam set as true, 1 beam pattern path needed");
142 string tmp_tx = ((
char *) argv[2]);
143 string tmp_rx = ((
char *) argv[3]);
144 if (tmp_tx.size() == 0 || tmp_rx.size() == 0) {
145 fprintf(stderr,
"Empty string for the file name");
148 std::cout <<
"Use different LUTs for tx and rx" << std::endl;
169 hdr_MPhy *ph = HDR_MPHY(p);
170 Position *source = ph->srcPosition;
171 Position *destination = ph->dstPosition;
172 double dist = source->getDist(destination);
175 if ((PktRx == 0) && (txPending ==
false)) {
178 cout << NOW <<
" UwOpticalBeamPattern::startRx max_tx_range LUT = " << max_tx_range
179 <<
" distance = " << dist << endl;
180 if (max_tx_range > dist) {
181 if (ph->modulationType == MPhy_Bpsk::modid) {
187 cout << NOW <<
" UwOpticalBeamPattern::Drop Packet::Wrong modulation"
192 cout << NOW <<
" UwOpticalBeamPattern::Drop Packet::Distance = "
194 <<
", Above Max Range = " << max_tx_range
199 cout << NOW <<
" UwOpticalBeamPattern::Drop Packet::Synced onto another packet "
201 << PktRx <<
", pending = " << txPending << endl;
215 cout << NOW <<
" UwOpticalBeamPattern::getMaxTxRange c = "
223 hdr_MPhy *ph = HDR_MPHY(p);
224 Position *dest = ph->dstPosition;
225 double dest_depth =
use_woss_ ? -dest->getAltitude() : -dest->getZ();
230 cerr <<
"UwOpticalBeamPattern::getMaxTxRange error: LUTs not init." << endl;
235 cout << NOW <<
" UwOpticalBeamPattern::getMaxTxRange max_distance LUT = "
236 << max_distance << endl;
243 cout << NOW <<
" UwOpticalBeamPattern::getMaxTxRange norm_beam_factor = "
244 << norm_beam_factor_rx <<
", beta = " << beta << endl;
248 cout << NOW <<
" UwOpticalBeamPattern::getMaxTxRange norm_beam_factor_xy = "
249 << norm_beam_factor_xy_rx <<
", beta_xy = " << beta_xy << endl;
250 return max_distance * norm_beam_factor_rx * norm_beam_factor_xy_rx
251 * norm_beam_factor_tx * norm_beam_factor_xy_tx;
257 bool omnidirectional =
259 if(omnidirectional) {
262 hdr_MPhy *ph = HDR_MPHY(p);
263 Position *rx = ph->dstPosition;
264 Position *tx = ph->srcPosition;
265 double rx_x =
use_woss_ ? rx->getLongitude() : rx->getX();
266 double tx_x =
use_woss_ ? tx->getLongitude() : tx->getX();
267 double rx_y =
use_woss_ ? rx->getLatitude() : rx->getY();
268 double tx_y =
use_woss_ ? tx->getLatitude() : tx->getY();
269 double rx_depth =
use_woss_ ? rx->getAltitude() : rx->getZ();
270 double tx_depth =
use_woss_ ? tx->getAltitude() : tx->getZ();
271 double dx = tx_x - rx_x;
272 double dy = tx_y - rx_y;
273 double dz = tx_depth - rx_depth;
276 double dy_prime = dy;
278 double dist_xy = sqrt(dx_prime*dx_prime + dy_prime*dy_prime);
281 beta = dz_prime > 0 ? M_PI/2 : - M_PI/2;
286 : atan(dz_prime/dist_xy);
288 beta = dz_prime == 0 ? 0 : beta;
291 beta = beta > 0 ? beta - M_PI : beta + M_PI;
293 beta = beta > M_PI ? beta - 2 * M_PI
294 : beta < -M_PI ? beta + 2 * M_PI : beta;
302 bool omnidirectional =
304 if(omnidirectional) {
307 hdr_MPhy *ph = HDR_MPHY(p);
308 Position *rx = ph->dstPosition;
309 Position *tx = ph->srcPosition;
310 double rx_x =
use_woss_ ? rx->getLongitude() : rx->getX();
311 double tx_x =
use_woss_ ? tx->getLongitude() : tx->getX();
312 double rx_y =
use_woss_ ? rx->getLatitude() : rx->getY();
313 double tx_y =
use_woss_ ? tx->getLatitude() : tx->getY();
314 double rx_depth =
use_woss_ ? rx->getAltitude() : rx->getZ();
315 double tx_depth =
use_woss_ ? tx->getAltitude() : tx->getZ();
316 double dx = tx_x - rx_x;
317 double dy = tx_y - rx_y;
318 double dz = tx_depth - rx_depth;
321 double dy_prime = dy;
327 beta_xy = dy_prime > 0 ? M_PI/2 : - M_PI/2;
330 beta_xy= atan((dy_prime)/(dx_prime));
332 beta_xy = dy_prime == 0 ? 0 : beta_xy;
342 bool omnidirectional =
344 if(omnidirectional) {
350 hdr_MPhy *ph = HDR_MPHY(p);
351 Position *tx = ph->srcPosition;
352 Position *rx = ph->dstPosition;
353 double tx_x =
use_woss_ ? tx->getLongitude() : tx->getX();
354 double rx_x =
use_woss_ ? rx->getLongitude() : rx->getX();
355 double tx_y =
use_woss_ ? tx->getLatitude() : tx->getY();
356 double rx_y =
use_woss_ ? rx->getLatitude() : rx->getY();
357 double tx_depth =
use_woss_ ? tx->getAltitude() : tx->getZ();
358 double rx_depth =
use_woss_ ? rx->getAltitude() : rx->getZ();
359 double dx = rx_x - tx_x;
360 double dy = rx_y - tx_y;
361 double dz = rx_depth - tx_depth;
364 double dy_prime = dy;
368 beta_xy = dy_prime > 0 ? M_PI/2 : - M_PI/2;
371 beta_xy= atan((dy_prime)/(dx_prime));
373 beta_xy = dy_prime == 0 ? 0 : beta_xy;
382 double max_distance = 0;
385 if (c_dist_it->first > c && c_dist_it !=
dist_lut_.begin()) {
387 c_dist_it->second.max_range_with_noise :
388 c_dist_it->second.max_range;
389 double c_next = c_dist_it->first;
392 c_dist_it->second.max_range_with_noise :
393 c_dist_it->second.max_range;
394 double c_prev = c_dist_it->first;
399 c_dist_it->second.max_range_with_noise :
400 c_dist_it->second.max_range;
408 double beam_norm_d = 0;
410 assert(beam_it != beam_lut_.end());
411 if (beam_it->first > beta && beam_it != beam_lut_.begin()) {
412 double dist_next = beam_it->second;
413 double beta_next = beam_it->first;
415 double dist_prev = beam_it->second;
416 double beta_prev = beam_it->first;
420 beam_norm_d = beam_it->second;
436 ifstream input_file_;
438 input_file_.open(beam_pattern_path_.c_str());
439 if (input_file_.is_open()) {
442 while (std::getline(input_file_, line_)) {
443 ::std::stringstream line_stream(line_);
451 cerr <<
"Impossible to open file " << beam_pattern_path_ << endl;
458 ifstream input_file_;
461 if (input_file_.is_open()) {
465 while (std::getline(input_file_, line_)) {
466 ::std::stringstream line_stream(line_);
488 UwOpticalPhy::startTx(p);
502 hdr_MPhy *ph = HDR_MPHY(p);
503 Position *tx = ph->srcPosition;
504 Position *rx = ph->dstPosition;
505 double tx_x =
use_woss_ ? tx->getLongitude() : tx->getX();
506 double rx_x =
use_woss_ ? rx->getLongitude() : rx->getX();
507 double tx_y =
use_woss_ ? tx->getLatitude() : tx->getY();
508 double rx_y =
use_woss_ ? rx->getLatitude() : rx->getY();
509 double tx_depth =
use_woss_ ? tx->getAltitude() : tx->getZ();
510 double rx_depth =
use_woss_ ? rx->getAltitude() : rx->getZ();
511 double dx = rx_x - tx_x;
512 double dy = rx_y - tx_y;
513 double dz = rx_depth - tx_depth;
516 double dy_prime = dy;
518 double dist_xy = sqrt(dx_prime*dx_prime + dy_prime*dy_prime);
521 beta = dz_prime > 0 ? M_PI/2 : - M_PI/2;
526 : atan(dz_prime/dist_xy);
528 beta = dz_prime == 0 ? 0 : beta;
530 beta = beta > 0 ? beta - M_PI : beta + M_PI;
532 beta = beta > M_PI ? beta - 2 * M_PI
533 : beta < -M_PI ? beta + 2 * M_PI : beta;
TclObject * create(int, const char *const *)
UwOpticalBeamPatternClass()
string beam_pattern_path_rx_
double getMaxTxRange(Packet *p)
Get the transmission range in the current conditions.
void initializeLUT()
Inizialize all the LUTs.
char beam_pattern_separator_
virtual void startRx(Packet *p)
double getBetaXYRx(Packet *p)
void initializeBeamLUT(BeamPattern &beam_lut_, string beam_pattern_path_)
Inizialize beam pattern LUT.
double inclination_angle_
Angle of inclination from the 0 Zenith.
double getLutMaxDist(double c, double na)
Get the maximum transmission range for these water properties.
string beam_pattern_path_tx_
double getLutBeamFactor(BeamPattern &beam_lut_, double beta)
void checkInclinationAngle()
double getBetaXYTx(Packet *p)
virtual int command(int, const char *const *)
TCL command interpreter.
double getBetaRx(Packet *p)
void initializeMaxRangeLUT()
Inizialize max range LUT.
virtual void startTx(Packet *p)
double back_noise_threshold_
double getBetaTx(Packet *p)
UwOpticalBeamPattern()
Constructor of UwMultiPhy class.
Class used to represents the UWOPTICAL_MPROPAGATION.
virtual void initializeLUT()
Inizialize LUT of c_variable values.
virtual double lookUpLightNoiseE(double depth)
bool use_woss_
Flag to set whether woss is employed.
virtual int command(int, const char *const *)
TCL command interpreter.
virtual double linearInterpolator(double x, double x1, double y1, double x2, double y2)
double max_range_with_noise
double & get_inclination_angle()
Definition of UwOpticalMPropagation class.
#define HDR_UWOPTICALBEAMPATTERN(p)
UwOpticalBeamPatternClass class_module_optical
Definition of UwOptical class.
CMaxDist::iterator CMaxDistIter
BeamPattern::iterator BeamPatternIter
::std::map< double, double > BeamPattern