FlightGear next
radio.hxx
Go to the documentation of this file.
1// radio.hxx -- FGRadio: class to manage radio propagation
2//
3// Written by Adrian Musceac YO8RZZ, started August 2011.
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License as
7// published by the Free Software Foundation; either version 2 of the
8// License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful, but
11// WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
19#pragma once
20
21#ifndef __cplusplus
22# error This library requires C++
23#endif
24
25#include <simgear/compiler.h>
26#include <simgear/structure/subsystem_mgr.hxx>
27#include <deque>
28#include <Main/fg_props.hxx>
29
30#include <simgear/math/sg_geodesy.hxx>
31#include <simgear/debug/logstream.hxx>
32#include "antenna.hxx"
33
34
36{
37private:
38
39 double _receiver_sensitivity;
40 double _transmitter_power;
41 double _tx_antenna_height;
42 double _rx_antenna_height;
43 double _rx_antenna_gain;
44 double _tx_antenna_gain;
45 double _rx_line_losses;
46 double _tx_line_losses;
47
48 double _terrain_sampling_distance;
49 int _polarization;
50 std::map<std::string, double[2]> _mat_database;
51 SGPropertyNode *_root_node;
52 int _propagation_model;
53 double polarization_loss();
54
55
56/*** Implement radio attenuation
57* based on the Longley-Rice propagation model
58* 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
59* @param: transmitter position, frequency, flag to indicate if the transmission is from a ground station
60* @return: signal level above receiver treshhold sensitivity
61***/
62 double ITM_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air);
63
64/*** a simple alternative LOS propagation model (WIP)
65* @param: transmitter position, frequency, flag to indicate if the transmission is from a ground station
66* @return: signal level above receiver treshhold sensitivity
67***/
68 double LOS_calculate_attenuation(SGGeod tx_pos, double freq, int ground_to_air);
69
70/*** Calculate losses due to vegetation and urban clutter (WIP)
71* We are only worried about clutter loss, terrain influence
72* on the first Fresnel zone is calculated in the ITM functions
73* @param: frequency, elevation data, terrain type, horizon distances, calculated loss
74* @return: none
75***/
76 void calculate_clutter_loss(double freq, double itm_elev[], std::deque<std::string*> &materials,
77 double transmitter_height, double receiver_height, int p_mode,
78 double horizons[], double &clutter_loss);
79
80/*** Temporary material properties database
81* @param: terrain type, median clutter height, radiowave attenuation factor
82* @return: none
83***/
84 void get_material_properties(std::string* mat_name, double &height, double &density);
85
86
87public:
88
91
95 void setFrequency(double freq, int radio);
96 double getFrequency(int radio);
97 inline void setTxPower(double txpower) { _transmitter_power = txpower; };
98 inline void setRxSensitivity(double sensitivity) { _receiver_sensitivity = sensitivity; };
99 inline void setTxAntennaHeight(double tx_antenna_height) { _tx_antenna_height = tx_antenna_height; };
100 inline void setRxAntennaHeight(double rx_antenna_height) { _rx_antenna_height = rx_antenna_height; };
101 inline void setTxAntennaGain(double tx_antenna_gain) { _tx_antenna_gain = tx_antenna_gain; };
102 inline void setRxAntennaGain(double rx_antenna_gain) { _rx_antenna_gain = rx_antenna_gain; };
103 inline void setTxLineLosses(double tx_line_losses) { _tx_line_losses = tx_line_losses; };
104 inline void setRxLineLosses(double rx_line_losses) { _rx_line_losses = rx_line_losses; };
105 inline void setPropagationModel(int model) { _propagation_model = model; };
106 inline void setPolarization(int polarization) { _polarization = polarization; };
107
109 static double watt_to_dbm(double power_watt);
110 static double dbm_to_watt(double dbm);
111 static double dbm_to_microvolt(double dbm);
112
113
114/*** Receive ATC radio communication as text
115* 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
116* @param: transmitter position, frequency, ATC text, flag to indicate whether the transmission comes from an ATC groundstation
117* @return: none
118***/
119 void receiveATC(SGGeod tx_pos, double freq, std::string text, int transmission_type);
120
121/*** TODO: receive multiplayer chat message and voice
122* @param: transmitter position, frequency, ATC text, flag to indicate whether the transmission comes from an ATC groundstation
123* @return: none
124***/
125 void receiveChat(SGGeod tx_pos, double freq, std::string text, int transmission_type);
126
127/*** TODO: receive navaid
128* @param: transmitter position, frequency, flag
129* @return: signal level above receiver treshhold sensitivity
130***/
131 double receiveNav(SGGeod tx_pos, double freq, int transmission_type);
132
133/*** Call this function to receive an arbitrary signal
134* for instance via the Nasal radioTransmission() function
135* returns the signal value above receiver sensitivity treshhold
136* @param: transmitter position, object heading in degrees (for antenna), object pitch angle in degrees
137* @return: signal level above receiver treshhold sensitivity
138***/
139 double receiveBeacon(SGGeod &tx_pos, double heading, double pitch);
140};
void receiveATC(SGGeod tx_pos, double freq, std::string text, int transmission_type)
Definition radio.cxx:141
double getFrequency(int radio)
Definition radio.cxx:76
void setTxAntennaGain(double tx_antenna_gain)
Definition radio.hxx:101
void setRxSensitivity(double sensitivity)
Definition radio.hxx:98
double receiveNav(SGGeod tx_pos, double freq, int transmission_type)
Definition radio.cxx:98
static double dbm_to_watt(double dbm)
Definition radio.cxx:1015
void setRxLineLosses(double rx_line_losses)
Definition radio.hxx:104
void receiveChat(SGGeod tx_pos, double freq, std::string text, int transmission_type)
Definition radio.cxx:93
double receiveBeacon(SGGeod &tx_pos, double heading, double pitch)
Definition radio.cxx:115
void setRxAntennaHeight(double rx_antenna_height)
Definition radio.hxx:100
void setPropagationModel(int model)
Definition radio.hxx:105
static double dbm_to_microvolt(double dbm)
Definition radio.cxx:1019
void setPolarization(int polarization)
Definition radio.hxx:106
void setTxPower(double txpower)
Definition radio.hxx:97
void setRxAntennaGain(double rx_antenna_gain)
Definition radio.hxx:102
void setTxAntennaHeight(double tx_antenna_height)
Definition radio.hxx:99
static double watt_to_dbm(double power_watt)
static convenience functions for unit conversions
Definition radio.cxx:1011
void setTxLineLosses(double tx_line_losses)
Definition radio.hxx:103
void setFrequency(double freq, int radio)
a couple of setters and getters for convenience, call after initializing frequency is in MHz,...