-double FGATCController::calculate_attenuation(FGTrafficRecord * rec, FGAirportDynamics *parent,
- int ground_to_air) {
- //////////////////////////////////////////////////
- /// Implement radio attenuation //
- /// based on the Longley-Rice propagation model//
- //////////////////////////////////////////////////
-
- FGScenery * scenery = globals->get_scenery();
- // player aircraft position
- double own_lat = fgGetDouble("/position/latitude-deg");
- double own_lon = fgGetDouble("/position/longitude-deg");
- double own_alt_ft = fgGetDouble("/position/altitude-ft");
- double own_alt= own_alt_ft * SG_FEET_TO_METER;
-
- cerr << "ITM:: pilot Lat: " << own_lat << ", Lon: " << own_lon << ", Alt: " << own_alt << endl;
-
- SGGeod own_pos = SGGeod::fromDegM( own_lon, own_lat, own_alt );
- SGGeod max_own_pos = SGGeod::fromDegM( own_lon, own_lat, SG_MAX_ELEVATION_M );
- SGGeoc center = SGGeoc::fromGeod( max_own_pos );
- SGGeoc own_pos_c = SGGeoc::fromGeod( own_pos );
-
- // position of sender radio antenna (HAAT)
- // sender can be aircraft or ground station
- double ATC_HAAT = 30.0;
- double Aircraft_HAAT = 7.0;
- double sender_alt_ft,sender_alt;
- double transceiver_height=0.0;
- double receiver_height=0.0;
- SGGeod sender_pos;
- if(ground_to_air) {
- sender_alt_ft = parent->getElevation();
- sender_alt = sender_alt_ft * SG_FEET_TO_METER + ATC_HAAT;
- sender_pos= SGGeod::fromDegM( parent->getLongitude(),
- parent->getLatitude(), sender_alt );
- }
- else {
- sender_alt_ft = rec->getAltitude();
- sender_alt = sender_alt_ft * SG_FEET_TO_METER + Aircraft_HAAT;
- sender_pos= SGGeod::fromDegM( rec->getLongitude(),
- rec->getLatitude(), sender_alt );
- }
- SGGeoc sender_pos_c = SGGeoc::fromGeod( sender_pos );
- cerr << "ITM:: sender Lat: " << parent->getLatitude() << ", Lon: " << parent->getLongitude() << ", Alt: " << sender_alt << endl;
-
- double point_distance= 90.0; // regular SRTM is 90 meters
- double course = SGGeodesy::courseRad(own_pos_c, sender_pos_c);
- double distance_m = SGGeodesy::distanceM(own_pos, sender_pos);
- double probe_distance = 0.0;
-
- cerr << "ITM:: Distance: " << distance_m << endl;
-
- double max_points = distance_m / point_distance;
- deque<double> _elevations;
-
- SGGeod probe_pilot = SGGeod::fromGeoc(center.advanceRadM( course, 0 ));
- double elevation_under_pilot = 0.0;
- if (scenery->get_elevation_m( probe_pilot, elevation_under_pilot, NULL )) {
- receiver_height = own_alt - elevation_under_pilot;
- }
- _elevations.push_front(receiver_height);
-
- SGGeod probe_sender = SGGeod::fromGeoc(center.advanceRadM( course, distance_m ));
- double elevation_under_sender = 0.0;
- if (scenery->get_elevation_m( probe_sender, elevation_under_sender, NULL )) {
- transceiver_height = sender_alt - elevation_under_sender;
- }
-
- // If distance larger than this value (400 km), assume reception imposssible
- // technically 400 km is no problem if LOS conditions exist,
- // but we do this to spare resources
- if (distance_m > 400000)
- return -1.0;
-
- int e_size = (deque<unsigned>::size_type)max_points;
-
- while (_elevations.size() < e_size) {
- probe_distance += point_distance;
- SGGeod probe = SGGeod::fromGeoc(center.advanceRadM( course, probe_distance ));
-
- double elevation_m = 0.0;
-
- if (scenery->get_elevation_m( probe, elevation_m, NULL )) {
- _elevations.push_front(elevation_m);
- //cerr << "ITM:: Probe elev: " << elevation_m << endl;
- }
- }
-
- _elevations.push_front(transceiver_height);
- double max_alt_between=0.0;
- for( deque<double>::size_type i = 0; i < _elevations.size(); i++ ) {
- if (_elevations[i] > max_alt_between) {
- max_alt_between = _elevations[i];
- }
- }
-
- double num_points= (double)_elevations.size();
- cerr << "ITM:: Max alt between: " << max_alt_between << ", num points:" << num_points << endl;
- _elevations.push_front(point_distance);
- _elevations.push_front(num_points -1);
- int size = _elevations.size();
- double itm_elev[size];
- for(int i=0;i<size;i++) {
- itm_elev[i]=_elevations[i];
- //cerr << "ITM:: itm_elev: " << _elevations[i] << endl;
- }
-
- ////////////// ITM default parameters //////////////
- // later perhaps take them from tile materials?
- double eps_dielect=15.0;
- double sgm_conductivity = 0.005;
- double eno = 301.0;
- double frq_mhz = 125.0; // middle of bandplan
- int radio_climate = 5; // continental temperate
- int pol=1; // assuming vertical polarization
- double conf = 0.90; // my own tests in Radiomobile have worked best with these values
- double rel = 0.80; // ^^
- double dbloss;
- char strmode[150];
- int errnum;
-
- /////////// radio parameters ///////////
- double receiver_sensitivity = -112.0; // typical AM receiver sensitivity in dBm
- // AM transmitter power in dBm.
- // Note this value is calculated from the typical final transistor stage output
- // !!! small aircraft have portable transmitters which operate at 36 dBm output (4 Watts)
- // later store this value in aircraft description
- // ATC comms usually operate high power equipment, thus making the link asymetrical; this is ignored for now
- if(ground_to_air)
- double transmitter_power = 49.0;
- else
- double transmitter_power = 43.0;
- if(ground_to_air)
- double antenna_gain = 5.0; //pilot plane's antenna gain + Controller antenna gain
- else
- double antenna_gain = 2.0; //pilot plane's antenna gain + AI aircraft antenna gain
- double link_budget = transmitter_power - receiver_sensitivity + antenna_gain;
-
-
- // first Fresnel zone radius
- // frequency in the middle of the bandplan, more accuracy is not necessary
- double fz_clr= 8.657 * sqrt(distance_m / 0.125);
-
- // TODO: If we clear the first Fresnel zone, we are into line of sight teritory
-
- // else we need to calculate point to point link loss
-
- point_to_point(itm_elev, sender_alt, own_alt,
- eps_dielect, sgm_conductivity, eno, frq_mhz, radio_climate,
- pol, conf, rel, dbloss, strmode, errnum);
-
- cerr << "ITM:: Attenuation: " << dbloss << " dBm, " << strmode << ", Error: " << errnum << endl;
-
- //if (errnum !=0 && errnum !=1)
- // return -1;
- double snr = link_budget - dbloss;
- return snr;
-
-}