FGRadioTransmission::FGRadioTransmission() {
- _receiver_sensitivity = -105.0; // typical AM receiver sensitivity seems to be 0.8 microVolt at 12dB SINAD
+ _receiver_sensitivity = -105.0; // typical AM receiver sensitivity seems to be 0.8 microVolt at 12dB SINAD or less
/** AM transmitter power in dBm.
* Typical output powers for ATC ground equipment, VHF-UHF:
return freq;
}
-/*** TODO: receive multiplayer chat message and voice
-***/
+
void FGRadioTransmission::receiveChat(SGGeod tx_pos, double freq, string text, int ground_to_air) {
}
-/*** TODO: receive navaid
-***/
+
double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmission_type) {
- // typical VOR/LOC transmitter power appears to be 200 Watt ~ 53 dBm
+ // typical VOR/LOC transmitter power appears to be 100 - 200 Watt i.e 50 - 53 dBm
// vor/loc typical sensitivity between -107 and -101 dBm
// glideslope sensitivity between -85 and -81 dBm
if ( _propagation_model == 1) {
}
-double FGRadioTransmission::receiveBeacon(double lat, double lon, double elev, double heading, double pitch) {
+
+double FGRadioTransmission::receiveBeacon(SGGeod &tx_pos, double heading, double pitch) {
+
+ // these properties should be set by an instrument
+ _receiver_sensitivity = _root_node->getDoubleValue("station[0]/rx-sensitivity", _receiver_sensitivity);
+ _transmitter_power = watt_to_dbm(_root_node->getDoubleValue("station[0]/tx-power-watt", _transmitter_power));
+ _polarization = _root_node->getIntValue("station[0]/polarization", 1);
+ _tx_antenna_height += _root_node->getDoubleValue("station[0]/tx-antenna-height", 0);
+ _rx_antenna_height += _root_node->getDoubleValue("station[0]/rx-antenna-height", 0);
+ _tx_antenna_gain += _root_node->getDoubleValue("station[0]/tx-antenna-gain", 0);
+ _rx_antenna_gain += _root_node->getDoubleValue("station[0]/rx-antenna-gain", 0);
+ double freq = _root_node->getDoubleValue("station[0]/frequency", 144.8); // by default stay in the ham 2 meter band
- _transmitter_power = 36;
- _tx_antenna_height += 0.0;
- _tx_antenna_gain += 0.5;
- elev = elev * SG_FEET_TO_METER;
- double freq = _root_node->getDoubleValue("station[0]/frequency", 118.0);
- int ground_to_air = 1;
- string text = "Beacon1";
double comm1 = getFrequency(1);
double comm2 = getFrequency(2);
if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) {
return -1;
}
- SGGeod tx_pos = SGGeod::fromDegM( lon, lat, elev );
- double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
+
+ double signal = ITM_calculate_attenuation(tx_pos, freq, 1);
return signal;
}
-/*** Receive ATC radio communication as text
-***/
+
void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) {
-
+ // adjust some default parameters in case the ATC code does not set them
if(ground_to_air == 1) {
_transmitter_power += 4.0;
_tx_antenna_height += 30.0;
_tx_antenna_gain += 2.0;
}
-
double comm1 = getFrequency(1);
double comm2 = getFrequency(2);
if ( !(fabs(freq - comm1) <= 0.0001) && !(fabs(freq - comm2) <= 0.0001) ) {
}
else {
- if ( _propagation_model == 0) {
- // skip propagation routines entirely
+ if ( _propagation_model == 0) { // skip propagation routines entirely
fgSetString("/sim/messages/atc", text.c_str());
}
- else if ( _propagation_model == 1 ) {
- // Use free-space, round earth
+ else if ( _propagation_model == 1 ) { // Use free-space, round earth
+
double signal = LOS_calculate_attenuation(tx_pos, freq, ground_to_air);
if (signal <= 0.0) {
return;
}
else {
-
fgSetString("/sim/messages/atc", text.c_str());
-
}
}
- else if ( _propagation_model == 2 ) {
- // Use ITM propagation model
+ else if ( _propagation_model == 2 ) { // Use ITM propagation model
+
double signal = ITM_calculate_attenuation(tx_pos, freq, ground_to_air);
if (signal <= 0.0) {
return;
}
if ((signal > 0.0) && (signal < 12.0)) {
- /** for low SNR values implement a way to make the conversation
+ /** for low SNR values need a way to make the conversation
* hard to understand but audible
* in the real world, the receiver AGC fails to capture the slope
* and the signal, due to being amplitude modulated, decreases volume after demodulation
text.replace(pos,1, hash_noise);
}
*/
- double volume = (fabs(signal - 12.0) / 12);
- double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
- SG_LOG(SG_GENERAL, SG_BULK, "Usable signal at limit: " << signal);
- //cerr << "Usable signal at limit: " << signal << endl;
- fgSetDouble("/sim/sound/voices/voice/volume", volume);
+ //double volume = (fabs(signal - 12.0) / 12);
+ //double old_volume = fgGetDouble("/sim/sound/voices/voice/volume");
+
+ //fgSetDouble("/sim/sound/voices/voice/volume", volume);
fgSetString("/sim/messages/atc", text.c_str());
- fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
+ //fgSetDouble("/sim/sound/voices/voice/volume", old_volume);
}
else {
fgSetString("/sim/messages/atc", text.c_str());
}
-
}
-
}
-
}
-/*** Implement radio attenuation
- based on the Longley-Rice propagation model
-***/
+
double FGRadioTransmission::ITM_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
double reverse_course = SGGeodesy::courseRad(sender_pos_c, own_pos_c);
double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
double probe_distance = 0.0;
- /** If distance larger than this value (300 km), assume reception imposssible */
+ /** If distance larger than this value (300 km), assume reception imposssible to spare CPU cycles */
if (distance_m > 300000)
return -1.0;
- /** If above 8000 meters, consider LOS mode and calculate free-space att */
+ /** If above 8000 meters, consider LOS mode and calculate free-space att to spare CPU cycles */
if (own_alt > 8000) {
dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
SG_LOG(SG_GENERAL, SG_BULK,
transmitter_height += _tx_antenna_height;
receiver_height += _rx_antenna_height;
-
- SG_LOG(SG_GENERAL, SG_BULK,
- "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters");
//cerr << "ITM:: RX-height: " << receiver_height << " meters, TX-height: " << transmitter_height << " meters, Distance: " << distance_m << " meters" << endl;
_root_node->setDoubleValue("station[0]/rx-height", receiver_height);
_root_node->setDoubleValue("station[0]/tx-height", transmitter_height);
for(int i=0;i<size;i++) {
itm_elev[i]=elevations[i];
-
-
}
if((transmission_type == 3) || (transmission_type == 4)) {
}
double pol_loss = 0.0;
+ // TODO: remove this check after we check a bit the axis calculations in this function
if (_polarization == 1) {
pol_loss = polarization_loss();
}
- SG_LOG(SG_GENERAL, SG_BULK,
- "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
+ //SG_LOG(SG_GENERAL, SG_BULK,
+ // "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum);
//cerr << "ITM:: Link budget: " << link_budget << ", Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
_root_node->setDoubleValue("station[0]/link-budget", link_budget);
_root_node->setDoubleValue("station[0]/terrain-attenuation", dbloss);
_root_node->setStringValue("station[0]/prop-mode", strmode);
_root_node->setDoubleValue("station[0]/clutter-attenuation", clutter_loss);
_root_node->setDoubleValue("station[0]/polarization-attenuation", pol_loss);
- //if (errnum == 4) // if parameters are outside sane values for lrprop, the alternative method is used
+ //if (errnum == 4) // if parameters are outside sane values for lrprop, bail out fast
// return -1;
+
+ // temporary, keep this antenna radiation pattern code here
double tx_pattern_gain = 0.0;
double rx_pattern_gain = 0.0;
- if (_root_node->getBoolValue("use-antenna-pattern", false)) {
- double sender_heading = 270.0; // due West
- double tx_antenna_bearing = sender_heading - reverse_course * SGD_RADIANS_TO_DEGREES;
- double rx_antenna_bearing = own_heading - course * SGD_RADIANS_TO_DEGREES;
- double rx_elev_angle = atan((itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m) * SGD_RADIANS_TO_DEGREES;
- double tx_elev_angle = 0.0 - rx_elev_angle;
+ double sender_heading = 270.0; // due West
+ double tx_antenna_bearing = sender_heading - reverse_course * SGD_RADIANS_TO_DEGREES;
+ double rx_antenna_bearing = own_heading - course * SGD_RADIANS_TO_DEGREES;
+ double rx_elev_angle = atan((itm_elev[2] + transmitter_height - itm_elev[(int)itm_elev[0] + 2] + receiver_height) / distance_m) * SGD_RADIANS_TO_DEGREES;
+ double tx_elev_angle = 0.0 - rx_elev_angle;
+ if (_root_node->getBoolValue("use-tx-antenna-pattern", false)) {
FGRadioAntenna* TX_antenna;
- FGRadioAntenna* RX_antenna;
TX_antenna = new FGRadioAntenna("Plot2");
TX_antenna->set_heading(sender_heading);
TX_antenna->set_elevation_angle(0);
tx_pattern_gain = TX_antenna->calculate_gain(tx_antenna_bearing, tx_elev_angle);
+ delete TX_antenna;
+ }
+ if (_root_node->getBoolValue("use-rx-antenna-pattern", false)) {
+ FGRadioAntenna* RX_antenna;
RX_antenna = new FGRadioAntenna("Plot2");
RX_antenna->set_heading(own_heading);
RX_antenna->set_elevation_angle(fgGetDouble("/orientation/pitch-deg"));
rx_pattern_gain = RX_antenna->calculate_gain(rx_antenna_bearing, rx_elev_angle);
-
- delete TX_antenna;
delete RX_antenna;
}
}
-/*** Calculate losses due to vegetation and urban clutter (WIP)
-* We are only worried about clutter loss, terrain influence
-* on the first Fresnel zone is calculated in the ITM functions
-***/
+
void FGRadioTransmission::calculate_clutter_loss(double freq, double itm_elev[], deque<string> &materials,
double transmitter_height, double receiver_height, int p_mode,
double horizons[], double &clutter_loss) {
}
}
- else if (p_mode == 2) { // troposcatter: ignore ground clutter for now...
+ else if (p_mode == 2) { // troposcatter: ignore ground clutter for now... maybe do something with weather
clutter_loss = 0.0;
}
}
-/*** Temporary material properties database
-* height: median clutter height
-* density: radiowave attenuation factor
-***/
+
void FGRadioTransmission::get_material_properties(string mat_name, double &height, double &density) {
if(mat_name == "Landmass") {
}
-/*** implement simple LOS propagation model (WIP)
-***/
+
double FGRadioTransmission::LOS_calculate_attenuation(SGGeod pos, double freq, int transmission_type) {
- double frq_mhz;
- if( (freq < 118.0) || (freq > 137.0) )
- frq_mhz = 125.0; // sane value, middle of bandplan
- else
- frq_mhz = freq;
+
+ double frq_mhz = freq;
double dbloss;
double tx_pow = _transmitter_power;
double ant_gain = _rx_antenna_gain + _tx_antenna_gain;
// free-space loss (distance calculation should be changed)
dbloss = 20 * log10(distance_m) +20 * log10(frq_mhz) -27.55;
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;
return signal;
class FGRadioTransmission
{
private:
- bool isOperable() const
- { return _operable; }
- bool _operable; ///< is the unit serviceable, on, powered, etc
double _receiver_sensitivity;
double _transmitter_power;
SGPropertyNode *_root_node;
int _propagation_model; /// 0 none, 1 round Earth, 2 ITM
double polarization_loss();
+
+
+/*** Implement radio attenuation
+* based on the Longley-Rice propagation model
+* ground_to_air: 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
+* @param: transmitter position, frequency, flag to indicate if the transmission is from a ground station
+* @return: signal level above receiver treshhold sensitivity
+***/
double ITM_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air);
+
+/*** a simple alternative LOS propagation model (WIP)
+* @param: transmitter position, frequency, flag to indicate if the transmission is from a ground station
+* @return: signal level above receiver treshhold sensitivity
+***/
double LOS_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air);
+
+/*** Calculate losses due to vegetation and urban clutter (WIP)
+* We are only worried about clutter loss, terrain influence
+* on the first Fresnel zone is calculated in the ITM functions
+* @param: frequency, elevation data, terrain type, horizon distances, calculated loss
+* @return: none
+***/
void calculate_clutter_loss(double freq, double itm_elev[], std::deque<string> &materials,
double transmitter_height, double receiver_height, int p_mode,
double horizons[], double &clutter_loss);
+
+/*** Temporary material properties database
+* @param: terrain type, median clutter height, radiowave attenuation factor
+* @return: none
+***/
void get_material_properties(string mat_name, double &height, double &density);
+
public:
FGRadioTransmission();
~FGRadioTransmission();
- // a couple of setters and getters for convenience
+ /// a couple of setters and getters for convenience, call after initializing
+ /// frequency is in MHz, sensitivity in dBm, antenna gain and losses in dB, transmitter power in dBm
+ /// polarization can be: 0 horizontal, 1 vertical
void setFrequency(double freq, int radio);
double getFrequency(int radio);
- void setTxPower(double txpower) { _transmitter_power = txpower; };
- void setRxSensitivity(double sensitivity) { _receiver_sensitivity = sensitivity; };
- void setTxAntennaHeight(double tx_antenna_height) { _tx_antenna_height = tx_antenna_height; };
- void setRxAntennaHeight(double rx_antenna_height) { _rx_antenna_height = rx_antenna_height; };
- void setTxAntennaGain(double tx_antenna_gain) { _tx_antenna_gain = tx_antenna_gain; };
- void setRxAntennaGain(double rx_antenna_gain) { _rx_antenna_gain = rx_antenna_gain; };
- void setTxLineLosses(double tx_line_losses) { _tx_line_losses = tx_line_losses; };
- 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 watt_to_dbm(double power_watt);
- double dbm_to_watt(double dbm);
- double dbm_to_microvolt(double dbm);
+ inline void setTxPower(double txpower) { _transmitter_power = txpower; };
+ inline void setRxSensitivity(double sensitivity) { _receiver_sensitivity = sensitivity; };
+ inline void setTxAntennaHeight(double tx_antenna_height) { _tx_antenna_height = tx_antenna_height; };
+ inline void setRxAntennaHeight(double rx_antenna_height) { _rx_antenna_height = rx_antenna_height; };
+ inline void setTxAntennaGain(double tx_antenna_gain) { _tx_antenna_gain = tx_antenna_gain; };
+ inline void setRxAntennaGain(double rx_antenna_gain) { _rx_antenna_gain = rx_antenna_gain; };
+ inline void setTxLineLosses(double tx_line_losses) { _tx_line_losses = tx_line_losses; };
+ inline void setRxLineLosses(double rx_line_losses) { _rx_line_losses = rx_line_losses; };
+ inline void setPropagationModel(int model) { _propagation_model = model; };
+ inline void setPolarization(int polarization) { _polarization = polarization; };
+
+ /// static convenience functions for unit conversions
+ static double watt_to_dbm(double power_watt);
+ static double dbm_to_watt(double dbm);
+ static 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
+/*** Receive ATC radio communication as text
+* 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
+* @param: transmitter position, frequency, ATC text, flag to indicate whether the transmission comes from an ATC groundstation
+* @return: none
+***/
void receiveATC(SGGeod tx_pos, double freq, string text, int transmission_type);
+
+/*** TODO: receive multiplayer chat message and voice
+* @param: transmitter position, frequency, ATC text, flag to indicate whether the transmission comes from an ATC groundstation
+* @return: none
+***/
void receiveChat(SGGeod tx_pos, double freq, string text, int transmission_type);
- // returns signal quality
- // transmission_type: 0 for VOR, 1 for ILS
+
+/*** TODO: receive navaid
+* @param: transmitter position, frequency, flag
+* @return: signal level above receiver treshhold sensitivity
+***/
double receiveNav(SGGeod tx_pos, double freq, int transmission_type);
- double receiveBeacon(double lat, double lon, double elev, double heading, double pitch);
+
+/*** Call this function to receive an arbitrary signal
+* for instance via the Nasal radioTransmission() function
+* returns the signal value above receiver sensitivity treshhold
+* @param: transmitter position, object heading in degrees (for antenna), object pitch angle in degrees
+* @return: signal level above receiver treshhold sensitivity
+***/
+ double receiveBeacon(SGGeod &tx_pos, double heading, double pitch);
};