]> git.mxchange.org Git - flightgear.git/commitdiff
Expose a radio function (receiveBeacon) to the Nasal subsystem
authoradrian <adrian@localhost.com>
Tue, 6 Dec 2011 19:03:40 +0000 (21:03 +0200)
committeradrian <adrian@localhost.com>
Tue, 6 Dec 2011 19:03:40 +0000 (21:03 +0200)
src/Radio/radio.cxx
src/Radio/radio.hxx
src/Scripting/NasalSys.cxx

index efe77b413fa35de039fc07bb458fbbb35696dc2b..3412a151b3fd48f1f5f6b7839073580200d13d0a 100644 (file)
@@ -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) {
index 81a6764a9c7777d8568e07a4bd14464396f5ca6b..06e05e9707dba67f70fca0ef8920a7aa661437f4 100644 (file)
@@ -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);
 };
 
 
index 0134dcb264ee1a621fb324c26f4e7353add2857e..d9a2cb6ff7753d3b260a18dd818b452734f06e91 100644 (file)
@@ -33,6 +33,7 @@
 #include <Scenery/scenery.hxx>
 #include <Navaids/navlist.hxx>
 #include <Navaids/procedure.hxx>
+#include <Radio/radio.hxx>
 
 
 #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; i<argc; i++) {
+        if(naIsNil(args[i]))
+               return naNil();
+    }
+    lat = naNumValue(args[0]).num;
+    lon = naNumValue(args[1]).num;
+    elev = naNumValue(args[2]).num;
+    heading = naNumValue(args[3]).num;
+    pitch = naNumValue(args[4]).num;
+    FGRadioTransmission *radio = new FGRadioTransmission;
+    double signal = radio->receiveBeacon(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 }
 };