diff --git a/src/Radio/radio.cxx b/src/Radio/radio.cxx index efe77b413..3412a151b 100644 --- a/src/Radio/radio.cxx +++ b/src/Radio/radio.cxx @@ -115,6 +115,28 @@ double FGRadioTransmission::receiveNav(SGGeod tx_pos, double freq, int transmiss } +double FGRadioTransmission::receiveBeacon(double lat, double lon, double elev, double heading, double pitch) { + + + _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); + + return signal; +} + + /*** Receive ATC radio communication as text ***/ void FGRadioTransmission::receiveATC(SGGeod tx_pos, double freq, string text, int ground_to_air) { diff --git a/src/Radio/radio.hxx b/src/Radio/radio.hxx index 81a6764a9..06e05e970 100644 --- a/src/Radio/radio.hxx +++ b/src/Radio/radio.hxx @@ -92,7 +92,7 @@ public: // returns signal quality // transmission_type: 0 for VOR, 1 for ILS double receiveNav(SGGeod tx_pos, double freq, int transmission_type); - + double receiveBeacon(double lat, double lon, double elev, double heading, double pitch); }; diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 0134dcb26..d9a2cb6ff 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -33,6 +33,7 @@ #include #include #include +#include #include "NasalSys.hxx" @@ -500,6 +501,26 @@ static naRef f_carttogeod(naContext c, naRef me, int argc, naRef* args) return vec; } +// Convert a cartesian point to a geodetic lat/lon/altitude. +static naRef f_radioTransmission(naContext c, naRef me, int argc, naRef* args) +{ + double lat, lon, elev, heading, pitch; + if(argc != 5) naRuntimeError(c, "radioTransmission() expects 5 arguments"); + for(int i=0; ireceiveBeacon(lat,lon,elev,heading,pitch); + delete radio; + return naNum(signal); +} + // Convert a geodetic lat/lon/altitude to a cartesian point. static naRef f_geodtocart(naContext c, naRef me, int argc, naRef* args) { @@ -805,6 +826,7 @@ static struct { const char* name; naCFunction func; } funcs[] = { { "geodinfo", f_geodinfo }, { "airportinfo", f_airportinfo }, { "navinfo", f_navinfo }, + { "radioTransmission", f_radioTransmission }, { 0, 0 } };