diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index 9f21a936e..0bc503dc9 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -871,10 +871,13 @@ double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, i if (distance_m > total_horizon) { return -1; } - + double pol_loss = 0.0; + if (_polarization == 1) { + pol_loss = polarization_loss(); + } // free-space loss (distance calculation should be changed) dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55; - signal = link_budget - dbloss; + signal = link_budget - dbloss + pol_loss; SG_LOG(SG_GENERAL, SG_BULK, "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm "); //cerr << "LOS:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm " << endl; @@ -912,3 +915,16 @@ double FGRadioTransmission::polarization_loss() { } +double FGRadioTransmission::power_to_dbm(double power_watt) { + return 10 * log10(1000 * power_watt); // returns dbm +} + +double FGRadioTransmission::dbm_to_power(double dbm) { + return exp( (dbm-30) * log(10) / 10); // returns Watts +} + +double FGRadioTransmission::dbm_to_microvolt(double dbm) { + return sqrt(dbm_to_power(dbm) * 50) * 1000000; // returns microvolts +} + + diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 92ce66fbc..619de3950 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -66,7 +66,7 @@ public: FGRadioTransmission(); ~FGRadioTransmission(); - + // a couple of setters and getters for convenience void setFrequency(double freq, int radio); double getFrequency(int radio); void setTxPower(double txpower) { _transmitter_power = txpower; }; @@ -79,6 +79,12 @@ public: void setRxLineLosses(double rx_line_losses) { _rx_line_losses = rx_line_losses; }; void setPropagationModel(int model) { _propagation_model = model; }; void setPolarization(int polarization) { _polarization = polarization; }; + // accessory functions for unit conversions + double power_to_dbm(double power_watt); + double dbm_to_power(double dbm); + double dbm_to_microvolt(double dbm); + + // transmission_type: 0 for air to ground 1 for ground to air, 2 for air to air, 3 for pilot to ground, 4 for pilot to air void receiveATC(SGGeod tx_pos, double freq, string text, int transmission_type); void receiveChat(SGGeod tx_pos, double freq, string text, int transmission_type);