On Dec 18, 2007 9:10 PM, Stuart Buchanan <[EMAIL PROTECTED]> wrote:
> Csaba wrote:
> > On Dec 18, 2007 6:53 PM, AnMaster wrote:
> > >
> > > Much better would be getting the closest airport with a
> > matching
> >
> tower frequency
> > > than just using the nearest airport.
> >
> > Excellent idea, I second that.
>
>
> Unfortunately this is a limitation of the Nasal interface to the airport
> information. At the moment, we can only retrieve the closest airport.
>
> It is a nice idea, and I will see whether the interface can be enhanced to
> include search criteria.
Attached patches (can be applied to both branches) expose a radio
transmitter search function for Nasal and update the chat-menu to use
it.
Known problems/limitations:
- not sure how to properly handle the case when no transmitter is found
- hardcoded to first comm frequency, should make that selectable or something
- the underlying FGCommList::FindByFreq function is not guaranteed to
return the nearest/strongest station (see comment there). Probably not
an issue.
- very limited number of approach and ground frequencies under data/ATC
- Nasal function could take more arguments for more detailed search
- the function name is a little misleading, any suggestions?
Comments welcome.
--
Csaba/Jester
Index: src/Scripting/NasalSys.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Scripting/NasalSys.cxx,v
retrieving revision 1.97
diff -u -r1.97 NasalSys.cxx
--- src/Scripting/NasalSys.cxx 5 Dec 2007 10:57:51 -0000 1.97
+++ src/Scripting/NasalSys.cxx 26 Dec 2007 01:51:10 -0000
@@ -30,6 +30,8 @@
#include <Main/fg_props.hxx>
#include <Scenery/scenery.hxx>
+#include <ATC/commlist.hxx>
+
#include "NasalSys.hxx"
static FGNasalSys* nasalSys = 0;
@@ -581,6 +583,46 @@
return aptdata;
}
+// Returns information about the nearest transmitter for the given frequency
+// or nil if none in range.
+static naRef f_findtransmitter(naContext c, naRef me, int argc, naRef* args)
+{
+ if (argc != 1 || !naIsNum(args[0])) naRuntimeError(c, "findtransmitter()
expects 1 argument: freq");
+
+ double lat = fgGetDouble("/position/latitude-deg");
+ double lon = fgGetDouble("/position/longitude-deg");
+ double elev = fgGetDouble("/position/altitude-ft");
+ double freq = args[0].num;
+
+ ATCData data;
+ bool found = current_commlist->FindByFreq(lon, lat, elev, freq, &data);
+
+ if (!found) {
+ return naNil();
+ }
+
+ naRef result = naNewHash(c);
+
+#define HASHSET(s,l,n) naHash_set(result, naStr_fromdata(naNewString(c),s,l),n)
+ HASHSET("ident", 4, naStr_fromdata(naNewString(c),
+ const_cast<char *>(data.ident.c_str()), data.ident.length()));
+ HASHSET("name", 4, naStr_fromdata(naNewString(c),
+ const_cast<char *>(data.name.c_str()), data.name.length()));
+
+ static const char* type_strings[] = { "invalid", "atis", "ground",
"tower", "approach", "departure", "enroute", "unknown" };
+ const int type_strings_count = sizeof(type_strings) / sizeof(const char*);
+ const char* type_string = data.type >= type_strings_count ?
type_strings[type_strings_count - 1] : type_strings[data.type];
+
+ HASHSET("type", 4, naStr_fromdata(naNewString(c),
+ const_cast<char *>(type_string), strlen(type_string)));
+
+ HASHSET("lat", 3, naNum(data.lat));
+ HASHSET("lon", 3, naNum(data.lon));
+ HASHSET("elevation", 9, naNum(data.elev));
+#undef HASHSET
+
+ return result;
+}
// Table of extension functions. Terminate with zeros.
static struct { const char* name; naCFunction func; } funcs[] = {
@@ -602,6 +644,7 @@
{ "geodtocart", f_geodtocart },
{ "geodinfo", f_geodinfo },
{ "airportinfo", f_airportinfo },
+ { "findtransmitter", f_findtransmitter },
{ 0, 0 }
};
Index: gui/dialogs/chat-menu.xml
===================================================================
RCS file: /var/cvs/FlightGear-0.9/data/gui/dialogs/chat-menu.xml,v
retrieving revision 1.2
diff -u -r1.2 chat-menu.xml
--- gui/dialogs/chat-menu.xml 11 Dec 2007 15:20:00 -0000 1.2
+++ gui/dialogs/chat-menu.xml 26 Dec 2007 01:54:28 -0000
@@ -160,9 +160,16 @@
# something appropriate, such as "Cessna", "Boeing".
type = split(" ", type)[0];
}
+
+ # Get the tuned-in station
+ var transmitter =
findtransmitter(getprop("/instrumentation/comm/frequencies/selected-mhz"));
+ if (transmitter == nil) {
+ gui.popupTip("No station in range.");
+ return;
+ }
# Get the nearest airport.
- var airport = airportinfo();
+ var airport = airportinfo(transmitter.lat, transmitter.lon);
# Get the complement of each runway to create a full set.
foreach (var rwy; keys(airport.runways)) {
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel