]> git.mxchange.org Git - flightgear.git/commitdiff
Add some functions to convert between various units
authoradrian <adrian@localhost.com>
Fri, 2 Dec 2011 17:13:53 +0000 (19:13 +0200)
committeradrian <adrian@localhost.com>
Fri, 2 Dec 2011 17:13:53 +0000 (19:13 +0200)
src/Radio/radio.cxx
src/Radio/radio.hxx

index 9f21a936edec25350ff2b6773480032991c36306..0bc503dc921a44cc28c459e525e5c5e27532dae0 100644 (file)
@@ -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
+}
+
+
index 92ce66fbc58197892d32d4a9c15dddeec3dd80bd..619de3950fe9366b9238866276fc116a81caab43 100644 (file)
@@ -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);