#include <iostream>
#include <simgear/math/SGMath.hxx>
+#include <Airports/dynamics.hxx>
+#include <Airports/simple.hxx>
+
#include "atc_mgr.hxx"
currentATCDialog = new FGATCDialogNew;
currentATCDialog->init();
+ // find a reasonable controller for our user's aircraft..
+ // Let's start by working out the following three scenarios:
+ // Starting on ground at a parking position
+ // Starting on ground at the runway.
+ // Starting in the Air
+ bool onGround = fgGetBool("/sim/presets/onground");
+ string runway = fgGetString("/sim/atc/runway");
+ string airport = fgGetString("/sim/presets/airport-id");
+ string parking = fgGetString("/sim/presets/parkpos");
+
+ FGAirport *apt = FGAirport::findByIdent(airport);
+ cerr << "found information: " << runway << " " << airport << ": parking = " << parking << endl;
+ if (onGround) {
+ if (parking.empty()) {
+ controller = apt->getDynamics()->getTowerController();
+ int stationFreq = apt->getDynamics()->getTowerFrequency(2);
+ cerr << "Setting radio frequency to in airfrequency: " << stationFreq << endl;
+ fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
+
+ } else {
+ controller = apt->getDynamics()->getGroundNetwork();
+ int stationFreq = apt->getDynamics()->getGroundFrequency(2);
+ cerr << "Setting radio frequency to : " << stationFreq << endl;
+ fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", ((double) stationFreq / 100.0));
+
+ }
+ } else {
+ controller = 0;
+ }
+ //controller =
+
//dialog.init();
}
void FGATCManager::update ( double time ) {
//cerr << "ATC update code is running at time: " << time << endl;
+ currentATCDialog->update(time);
}
{
private:
AtcVec activeStations;
+ FGATCController *controller; // The ATC controller that is responsible for the user's aircraft.
//FGATCDialogNew dialog; // note that this variable should really replace the ugly global "currentATCDialog();
public:
dialogVisible = !dialogVisible;
return;
}
+
+void FGATCDialogNew::update(double dt) {
+ static SGPropertyNode_ptr trans_num = globals->get_props()->getNode("/sim/atc/transmission-num", true);
+ int n = trans_num->getIntValue();
+ if (n >= 0) {
+ trans_num->setIntValue(-1);
+ // PopupCallback(n);
+ cerr << "Selected transmission message" << n << endl;
+ }
+}
\ No newline at end of file
dt_count = 0;
available = true;
lastTransmission = 0;
- FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
- mgr->addController(this);
+ initialized = false;
}
FGATCController::~FGATCController()
}
}
+void FGATCController::init()
+{
+ if (!initialized) {
+ FGATCManager *mgr = (FGATCManager*) globals->get_subsystem("ATC");
+ mgr->addController(this);
+ initialized = true;
+ }
+}
+
/***************************************************************************
* class FGTowerController
*
double radius, int leg,
FGAIAircraft * ref)
{
+ init();
TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
double radius, int leg,
FGAIAircraft * ref)
{
+ init();
TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
double alt, double radius,
int leg, FGAIAircraft * ref)
{
+ init();
TrafficVectorIterator i = activeTraffic.begin();
// Search whether the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route
*************************************************************************************/
class FGATCController
{
+private:
+ bool initialized;
protected:
bool available;
time_t lastTransmission;
ATC_GROUND_TO_AIR } AtcMsgDir;
FGATCController();
virtual ~FGATCController();
+ void init();
+
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
return groundFreq;
}
+int FGAirportDynamics::getTowerFrequency(unsigned nr)
+{
+ int towerFreq = 0;
+ if (nr < 2) {
+ SG_LOG(SG_ATC, SG_ALERT,
+ "Leg value is smaller than two at " << SG_ORIGIN);
+ }
+ if (freqTower.size() == 0) {
+ return 0;
+ }
+ if ((freqTower.size() > nr - 1) && (nr > 1)) {
+ towerFreq = freqTower[nr - 1];
+ }
+ if ((freqTower.size() < nr - 1) && (nr > 1)) {
+ towerFreq =
+ (freqTower.size() <
+ (nr - 1)) ? freqTower[freqTower.size() -
+ 1] : freqTower[nr - 2];
+ }
+ if ((freqTower.size() >= nr - 1) && (nr > 1)) {
+ towerFreq = freqTower[nr - 2];
+ }
+ return towerFreq;
+}
+
+
FGAIFlightPlan *FGAirportDynamics::getSID(string activeRunway,
double heading)
{
FGApproachController *getApproachController() { return &approachController; };
const string& getAtisInformation() { return atisInformation; };
- int getGroundFrequency(unsigned leg); //{ return freqGround.size() ? freqGround[0] : 0; };
-
+ int getGroundFrequency (unsigned leg); //{ return freqGround.size() ? freqGround[0] : 0; };
+ int getTowerFrequency (unsigned nr);
void setRwyUse(const FGRunwayPreference& ref);
};
double radius, int leg,
FGAIAircraft * aircraft)
{
+ init();
TrafficVectorIterator i = activeTraffic.begin();
// Search search if the current id alread has an entry
// This might be faster using a map instead of a vector, but let's start by taking a safe route