#include <Scripting/NasalSys.hxx>
#include <Sound/sample_queue.hxx>
#include <Airports/xmlloader.hxx>
+#include <ATC/CommStation.hxx>
+#include <Navaids/navrecord.hxx>
+#include <Navaids/navlist.hxx>
#include "fg_init.hxx"
#include "fg_io.hxx"
return true;
}
+static SGGeod commandSearchPos(const SGPropertyNode* arg)
+{
+ if (arg->hasChild("longitude-deg") && arg->hasChild("latitude-deg")) {
+ return SGGeod::fromDeg(arg->getDoubleValue("longitude-deg"),
+ arg->getDoubleValue("latitude-deg"));
+ }
+
+ // use current viewer/aircraft position
+ return SGGeod::fromDeg(fgGetDouble("/position/longitude-deg"),
+ fgGetDouble("/position/latitude-deg"));
+}
+
+static bool
+do_comm_search(const SGPropertyNode* arg)
+{
+ SGGeod pos = commandSearchPos(arg);
+ int khz = static_cast<int>(arg->getDoubleValue("frequency-mhz") * 100.0 + 0.25);
+
+ flightgear::CommStation* sta = flightgear::CommStation::findByFreq(khz, pos, NULL);
+ if (!sta) {
+ return true;
+ }
+
+ SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
+ sta->createBinding(result);
+ return true;
+}
+static bool
+do_nav_search(const SGPropertyNode* arg)
+{
+ SGGeod pos = commandSearchPos(arg);
+ double mhz = arg->getDoubleValue("frequency-mhz");
+
+ FGNavList* navList = globals->get_navlist();
+ string type(arg->getStringValue("type", "vor"));
+ if (type == "dme") {
+ navList = globals->get_dmelist();
+ } else if (type == "tacan") {
+ navList = globals->get_tacanlist();
+ }
+
+ FGNavRecord* nav = navList->findByFreq(mhz, pos);
+ if (!nav && (type == "vor")) {
+ // if we're searching VORs, look for localizers too
+ nav = globals->get_loclist()->findByFreq(mhz, pos);
+ }
+
+ if (!nav) {
+ return true;
+ }
+
+ SGPropertyNode* result = fgGetNode(arg->getStringValue("result"));
+ nav->createBinding(result);
+ return true;
+}
+
////////////////////////////////////////////////////////////////////////
// Command setup.
////////////////////////////////////////////////////////////////////////
{ "dump-terrainbranch", do_dump_terrain_branch },
{ "print-visible-scene", do_print_visible_scene_info },
{ "reload-shaders", do_reload_shaders },
+
+ { "find-navaid", do_nav_search },
+ { "find-comm", do_comm_search },
+
{ 0, 0 } // zero-terminated
};
for (unsigned int c=0; c<apt->commStations().size(); ++c) {
flightgear::CommStation* comm = apt->commStations()[c];
std::string tynm = FGPositioned::nameForType(comm->type());
- int count = nd->getChildren(tynm).size();
- SGPropertyNode* commNode = nd->getChild(tynm, count, true);
- commNode->setStringValue("ident", comm->ident());
- commNode->setDoubleValue("frequency-mhz", comm->freqMHz());
- }
+ // for some standard frequence types, we don't care about the ident,
+ // so just list the frequencies under one group.
+ if ((comm->type() == FGPositioned::FREQ_ATIS) ||
+ (comm->type() == FGPositioned::FREQ_AWOS) ||
+ (comm->type() == FGPositioned::FREQ_TOWER) ||
+ (comm->type() == FGPositioned::FREQ_GROUND))
+ {
+ SGPropertyNode* commNode = nd->getChild(tynm, 0, true);
+ int count = nd->getChildren("frequency-mhz").size();
+ SGPropertyNode* freqNode = commNode->getChild("frequency-mhz", count, true);
+ freqNode->setDoubleValue(comm->freqMHz());
+ } else {
+ // for other kinds of frequency, there's more variation, so list the ID too
+ int count = nd->getChildren(tynm).size();
+ SGPropertyNode* commNode = nd->getChild(tynm, count, true);
+ commNode->setStringValue("ident", comm->ident());
+ commNode->setDoubleValue("frequency-mhz", comm->freqMHz());
+
+ }
+ } // of airprot comm stations iteration
}
CommStationBinding::CommStationBinding(const CommStation* sta, SGPropertyNode* node) :