1
0
Fork 0

Cleanup Inheritance in ATC

This commit is contained in:
portree_kid 2022-01-31 22:34:05 +01:00
parent 276835f74c
commit cf0d90ef3d
21 changed files with 408 additions and 488 deletions

View file

@ -48,7 +48,8 @@ using std::string;
using std::cerr;
using std::endl;
//#include <Airports/trafficcontroller.hxx>
#include <ATC/ATCController.hxx>
#include <ATC/trafficcontrol.hxx>
FGAIAircraft::FGAIAircraft(FGAISchedule* ref) : /* HOT must be disabled for AI Aircraft,
* otherwise traffic detection isn't working as expected.*/
@ -755,10 +756,8 @@ void FGAIAircraft::processATC(const FGATCInstruction& instruction) {
}
}
if (instruction.getChangeAltitude()) {}
}
void FGAIAircraft::handleFirstWaypoint() {
bool eraseWaypoints; //TODO YAGNI
headingError = 0;

View file

@ -81,6 +81,7 @@ public:
const std::string& getCompany() const { return company; }
void setCompany(const std::string& comp) { company = comp;};
//ATC
void announcePositionToController(); //TODO have to be public?
void processATC(const FGATCInstruction& instruction);
void setTaxiClearanceRequest(bool arg) { needsTaxiClearance = arg; };

View file

@ -79,6 +79,8 @@ FGATCController::~FGATCController()
auto mgr = globals->get_subsystem<FGATCManager>();
mgr->removeController(this);
}
_isDestroying = true;
clearTrafficControllers();
}
void FGATCController::init()
@ -124,7 +126,7 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
int ground_to_air=0;
//double commFreqD;
sender = rec->getAircraft()->getTrafficRef()->getCallSign();
sender = rec->getCallsign();
if (rec->getAircraft()->getTaxiClearanceRequest()) {
instructionText = "push-back and taxi";
} else {
@ -135,33 +137,17 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
auto depApt = rec->getAircraft()->getTrafficRef()->getDepartureAirport();
//FIXME Must be transferred to controller and fallback for GROUND -> TOWER if GROUND not set
switch (rec->getLeg()) {
case 1:
case 2:
// avoid crash FLIGHTGEAR-ER
if (!depApt) {
SG_LOG(SG_ATC, SG_DEV_ALERT, "TrafficRec has empty departure airport, can't transmit");
return;
}
freqId = rec->getNextFrequency();
stationFreq = depApt->getDynamics()->getGroundFrequency(rec->getLeg() + freqId);
taxiFreq = depApt->getDynamics()->getGroundFrequency(2);
towerFreq = depApt->getDynamics()->getTowerFrequency(2);
receiver = depApt->getName() + "-Ground";
atisInformation = depApt->getDynamics()->getAtisSequence();
break;
case 3:
if (!depApt) {
SG_LOG(SG_ATC, SG_DEV_ALERT, "TrafficRec has empty departure airport, can't transmit");
return;
}
receiver = depApt->getName() + "-Tower";
break;
if (!depApt) {
SG_LOG(SG_ATC, SG_DEV_ALERT, "TrafficRec has empty departure airport, can't transmit");
return;
}
stationFreq = getFrequency();
taxiFreq = depApt->getDynamics()->getGroundFrequency(2);
towerFreq = depApt->getDynamics()->getTowerFrequency(2);
receiver = getName();
atisInformation = depApt->getDynamics()->getAtisSequence();
// Swap sender and receiver value in case of a ground to air transmission
if (msgDir == ATC_GROUND_TO_AIR) {
string tmp = sender;
@ -306,6 +292,16 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
//text = "test2";
SG_LOG(SG_ATC, SG_DEBUG, "2 Currently at leg " << rec->getLeg());
break;
case MSG_CLEARED_FOR_TAKEOFF:
activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
//activeRunway = "test";
text = receiver + ". Cleared for takeoff runway " + activeRunway + ". " + sender + ".";
break;
case MSG_ACKNOWLEDGE_CLEARED_FOR_TAKEOFF:
activeRunway = rec->getAircraft()->GetFlightPlan()->getRunway();
text = receiver + " Roger. Cleared for takeoff runway " + activeRunway + ". " + sender + ".";
//text = "test2";
break;
case MSG_SWITCH_TOWER_FREQUENCY:
towerFreqStr = formatATCFrequency3_2(towerFreq);
text = receiver + " Contact Tower at " + towerFreqStr + ". " + sender + ".";
@ -333,6 +329,9 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
int onBoardRadioFreqI0 = (int) floor(onBoardRadioFreq0 * 100 + 0.5);
int onBoardRadioFreqI1 = (int) floor(onBoardRadioFreq1 * 100 + 0.5);
SG_LOG(SG_ATC, SG_DEBUG, "Using " << onBoardRadioFreq0 << ", " << onBoardRadioFreq1 << " and " << stationFreq << " for " << text << endl);
if( stationFreq == 0 ) {
SG_LOG(SG_ATC, SG_DEBUG, getName() << " stationFreq not found");
}
// Display ATC message only when one of the radios is tuned
// the relevant frequency.
@ -349,19 +348,17 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
SGGeod sender_pos;
double sender_alt_ft, sender_alt;
if(ground_to_air) {
sender_pos = parent->parent()->geod();
}
sender_pos = parent->parent()->geod();
}
else {
sender_alt_ft = rec->getAltitude();
sender_alt = sender_alt_ft * SG_FEET_TO_METER;
sender_pos= SGGeod::fromDegM( rec->getLongitude(),
rec->getLatitude(), sender_alt );
sender_pos= rec->getPos();
}
double frequency = ((double)stationFreq) / 100;
radio->receiveATC(sender_pos, frequency, text, ground_to_air);
delete radio;
}
else {
SG_LOG(SG_ATC, SG_BULK, "Transmitting " << text);
fgSetString("/sim/messages/atc", text.c_str());
}
}
@ -371,6 +368,48 @@ void FGATCController::transmit(FGTrafficRecord * rec, FGAirportDynamics *parent,
}
}
void FGATCController::signOff(int id)
{
TrafficVectorIterator i = searchActiveTraffic(id);
if (i == activeTraffic.end()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from " << getName() << " at " << SG_ORIGIN);
return;
}
activeTraffic.erase(i);
SG_LOG(SG_ATC, SG_DEBUG, i->getCallsign() << " signing off from " << getName() );
}
bool FGATCController::hasInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(id);
if (i == activeTraffic.end()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
return false;
}
FGATCInstruction FGATCController::getInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(id);
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
return FGATCInstruction();
}
/*
* Format integer frequency xxxyy as xxx.yy
* @param freq - integer value
@ -402,32 +441,33 @@ string FGATCController::genTransponderCode(const string& fltRules)
return std::to_string(val);
}
void FGATCController::eraseDeadTraffic(TrafficVector& vec)
void FGATCController::eraseDeadTraffic()
{
auto it = std::remove_if(vec.begin(), vec.end(), [](const FGTrafficRecord& traffic)
auto it = std::remove_if(activeTraffic.begin(), activeTraffic.end(), [](const FGTrafficRecord& traffic)
{
if (!traffic.getAircraft()) {
return true;
}
return traffic.getAircraft()->getDie();
return traffic.isDead();
});
vec.erase(it, vec.end());
activeTraffic.erase(it, activeTraffic.end());
}
void FGATCController::clearTrafficControllers(TrafficVector& vec)
/*
* Search activeTraffic vector to find matching id
* @param id integer to search for in the vector
* @return the matching item OR activeTraffic.end()
*/
TrafficVectorIterator FGATCController::searchActiveTraffic(int id)
{
for (const auto& traffic : vec) {
if (!traffic.getAircraft()) {
continue;
}
return std::find_if(activeTraffic.begin(), activeTraffic.end(),
[id] (const FGTrafficRecord& rec)
{ return rec.getId() == id; }
);
}
traffic.getAircraft()->clearATCController();
void FGATCController::clearTrafficControllers()
{
for (const auto& traffic : activeTraffic) {
traffic.clearATCController();
}
}
TrafficVectorIterator FGATCController::searchActiveTraffic(TrafficVector& vec, int id)
{
return std::find_if(vec.begin(), vec.end(), [id] (const FGTrafficRecord& rec)
{ return rec.getId() == id; });
}

View file

@ -28,8 +28,7 @@
#include <osg/Shape>
#include <simgear/compiler.h>
// There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
@ -46,19 +45,25 @@ private:
protected:
// guard variable to avoid modifying state during destruction
bool _isDestroying = false;
bool initialized;
bool available;
time_t lastTransmission;
TrafficVector activeTraffic;
double dt_count;
osg::Group* group;
FGAirportDynamics *parent = nullptr;
std::string formatATCFrequency3_2(int );
std::string genTransponderCode(const std::string& fltRules);
bool isUserAircraft(FGAIAircraft*);
void clearTrafficControllers(TrafficVector& vec);
TrafficVectorIterator searchActiveTraffic(TrafficVector& vec, int id);
void eraseDeadTraffic(TrafficVector& vec);
void clearTrafficControllers();
TrafficVectorIterator searchActiveTraffic(int id);
void eraseDeadTraffic();
/**Returns the frequency to be used. */
virtual int getFrequency() = 0;
public:
typedef enum {
MSG_ANNOUNCE_ENGINE_START,
@ -81,6 +86,8 @@ public:
MSG_ACKNOWLEDGE_RESUME_TAXI,
MSG_REPORT_RUNWAY_HOLD_SHORT,
MSG_ACKNOWLEDGE_REPORT_RUNWAY_HOLD_SHORT,
MSG_CLEARED_FOR_TAKEOFF,
MSG_ACKNOWLEDGE_CLEARED_FOR_TAKEOFF,
MSG_SWITCH_TOWER_FREQUENCY,
MSG_ACKNOWLEDGE_SWITCH_TOWER_FREQUENCY
} AtcMsgId;
@ -97,11 +104,19 @@ public:
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft) = 0;
virtual void signOff(int id) = 0;
virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt) = 0;
virtual bool hasInstruction(int id) = 0;
virtual FGATCInstruction getInstruction(int id) = 0;
void signOff(int id);
bool hasInstruction(int id);
FGATCInstruction getInstruction(int id);
bool hasActiveTraffic() {
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
double getDt() {
return dt_count;
@ -113,16 +128,10 @@ public:
std::string getGateName(FGAIAircraft *aircraft);
virtual void render(bool) = 0;
virtual std::string getName() = 0;
virtual void update(double) = 0;
protected:
// guard variable to avoid modifying state during destruction
bool _isDestroying = false;
private:
AtcMsgDir lastTransmissionDirection;
};

View file

@ -72,8 +72,6 @@ FGApproachController::FGApproachController(FGAirportDynamics *par):
FGApproachController::~FGApproachController()
{
_isDestroying = true;
clearTrafficControllers(activeTraffic);
}
@ -88,7 +86,7 @@ void FGApproachController::announcePosition(int id,
init();
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
// Add a new TrafficRecord if no one exsists for this aircraft.
if (i == activeTraffic.end() || activeTraffic.empty()) {
@ -98,7 +96,7 @@ void FGApproachController::announcePosition(int id,
rec.setPositionAndHeading(lat, lon, heading, speed, alt);
rec.setRunway(intendedRoute->getRunway());
rec.setLeg(leg);
//rec.setCallSign(callsign);
rec.setCallsign(ref->getCallSign());
rec.setAircraft(ref);
activeTraffic.push_back(rec);
} else {
@ -111,7 +109,7 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double
double dt)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
TrafficVectorIterator current;
// update position of the current aircraft
@ -122,85 +120,43 @@ void FGApproachController::updateAircraftInformation(int id, double lat, double
i->setPositionAndHeading(lat, lon, heading, speed, alt);
current = i;
SG_LOG(SG_ATC, SG_BULK, "ApproachController: checking for speed");
time_t time_diff =
current->getAircraft()->
checkForArrivalTime(string("final001"));
if (time_diff > 15) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
1.35);
} else if (time_diff > 5) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
1.2);
} else if (time_diff < -15) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
0.65);
} else if (time_diff < -5) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
0.8);
} else {
current->clearSpeedAdjustment();
if(current->getAircraft()) {
//FIXME No call to aircraft! -> set instruction
time_t time_diff =
current->getAircraft()->
checkForArrivalTime(string("final001"));
if (time_diff > 15) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
1.35);
} else if (time_diff > 5) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
1.2);
} else if (time_diff < -15) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
0.65);
} else if (time_diff < -5) {
current->setSpeedAdjustment(current->getAircraft()->
getPerformance()->vDescent() *
0.8);
} else {
current->clearSpeedAdjustment();
}
}
//current->setSpeedAdjustment(current->getAircraft()->getPerformance()->vDescent() + time_diff);
}
setDt(getDt() + dt);
}
/* Search for and erase traffic record with a specific id */
void FGApproachController::signOff(int id)
{
// ensure we don't modify activeTraffic during destruction
if (_isDestroying)
return;
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from approach at " << SG_ORIGIN);
} else {
i = activeTraffic.erase(i);
}
}
/* Periodically check for and remove dead traffic records */
void FGApproachController::update(double dt)
{
FGATCController::eraseDeadTraffic(activeTraffic);
FGATCController::eraseDeadTraffic();
}
bool FGApproachController::hasInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
return false;
}
FGATCInstruction FGApproachController::getInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
return FGATCInstruction();
}
ActiveRunway *FGApproachController::getRunway(const string& name)
@ -228,5 +184,11 @@ void FGApproachController::render(bool visible) {
}
string FGApproachController::getName() {
return string(parent->getId() + "-approach");
return string(parent->parent()->getName() + "-approach");
}
int FGApproachController::getFrequency() {
int groundFreq = parent->getApproachFrequency(2);
int towerFreq = parent->getTowerFrequency(2);
return groundFreq>0?groundFreq:towerFreq;
}

View file

@ -28,8 +28,7 @@
#include <osg/Shape>
#include <simgear/compiler.h>
// There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
@ -38,15 +37,14 @@
#include <ATC/trafficcontrol.hxx>
/******************************************************************************
* class FGTowerControl
* class FGApproachController
*****************************************************************************/
class FGApproachController : public FGATCController
{
private:
TrafficVector activeTraffic;
ActiveRunwayVec activeRunways;
FGAirportDynamics *parent;
/**Returns the frequency to be used. */
int getFrequency();
public:
FGApproachController(FGAirportDynamics * parent);
virtual ~FGApproachController();
@ -55,11 +53,8 @@ public:
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft);
virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
virtual std::string getName();
@ -67,12 +62,6 @@ public:
ActiveRunway* getRunway(const std::string& name);
bool hasActiveTraffic() {
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
};
#endif

View file

@ -67,31 +67,23 @@ using std::string;
/***************************************************************************
* FGGroundController()
**************************************************************************/
FGGroundController::FGGroundController() :
parent(NULL)
FGGroundController::FGGroundController(FGAirportDynamics *par)
{
hasNetwork = false;
count = 0;
currTraffic = activeTraffic.begin();
group = 0;
version = 0;
networkInitialized = false;
FGATCController::init();
parent = par;
hasNetwork = true;
networkInitialized = true;
}
FGGroundController::~FGGroundController()
{
_isDestroying = true;
}
void FGGroundController::init(FGAirportDynamics* aDynamics)
{
FGATCController::init();
dynamics = aDynamics;
parent = dynamics->parent();
hasNetwork = true;
networkInitialized = true;
}
bool compare_trafficrecords(FGTrafficRecord a, FGTrafficRecord b)
@ -99,19 +91,6 @@ bool compare_trafficrecords(FGTrafficRecord a, FGTrafficRecord b)
return (a.getIntentions().size() < b.getIntentions().size());
}
/*
* Search activeTraffic vector to find matching id
* @param id integer to search for in the vector
* @return the matching item OR activeTraffic.end()
*/
TrafficVectorIterator FGGroundController::searchActiveTraffic(int id)
{
return std::find_if(activeTraffic.begin(), activeTraffic.end(),
[id] (const FGTrafficRecord& rec)
{ return rec.getId() == id; }
);
}
void FGGroundController::announcePosition(int id,
FGAIFlightPlan * intendedRoute,
int currentPosition, double lat,
@ -126,7 +105,7 @@ void FGGroundController::announcePosition(int id,
}
// Search the activeTraffic vector to find a traffic vector with our id
TrafficVectorIterator i = searchActiveTraffic(id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
// Add a new TrafficRecord if none exists for this aircraft
// otherwise set the information for the TrafficRecord
@ -137,6 +116,7 @@ void FGGroundController::announcePosition(int id,
rec.setPositionAndIntentions(currentPosition, intendedRoute);
rec.setPositionAndHeading(lat, lon, heading, speed, alt);
rec.setRadius(radius); // only need to do this when creating the record.
rec.setCallsign(aircraft->getCallSign());
rec.setAircraft(aircraft);
// add to the front of the list of activeTraffic if the aircraft is already taxiing
if (leg == 2) {
@ -150,26 +130,6 @@ void FGGroundController::announcePosition(int id,
}
}
/*
Search for and erase an aircraft with a certain id from the activeTraffic vector
*/
void FGGroundController::signOff(int id)
{
if (_isDestroying)
return;
// Search the activeTraffic vector to find a traffic vector with our id
TrafficVectorIterator i = searchActiveTraffic(id);
// If one is found erase the record, else give an error message
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
SG_LOG(SG_GENERAL, SG_ALERT,
"AI error: Aircraft without traffic record is signing off at " << SG_ORIGIN);
} else {
i = activeTraffic.erase(i);
}
}
/*
* The ground network can deal with the following states:
* 0 = Normal; no action required
@ -200,11 +160,11 @@ bool FGGroundController::checkTransmissionState(int minState, int maxState, Traf
//FGATCDialogNew::instance()->removeEntry(1);
} else {
SG_LOG(SG_ATC, SG_DEBUG, "creating message for " << i->getAircraft()->getCallSign());
transmit(&(*i), dynamics, msgId, msgDir, false);
transmit(&(*i), parent, msgId, msgDir, false);
return false;
}
}
transmit(&(*i), dynamics, msgId, msgDir, true);
transmit(&(*i), parent, msgId, msgDir, true);
i->updateState();
lastTransmission = now;
available = false;
@ -224,7 +184,7 @@ void FGGroundController::updateAircraftInformation(int id, double lat, double lo
// Probably use a status mechanism similar to the Engine start procedure in the startup controller.
// Search the activeTraffic vector to find a traffic vector with our id
TrafficVectorIterator i = searchActiveTraffic(id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
// update position of the current aircraft
if (i == activeTraffic.end() || activeTraffic.empty()) {
@ -302,7 +262,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
TrafficVectorIterator current, closest, closestOnNetwork;
bool otherReasonToSlowDown = false;
// bool previousInstruction;
TrafficVectorIterator i = searchActiveTraffic(id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
if (!activeTraffic.size()) {
return;
}
@ -329,9 +289,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
continue;
}
SGGeod other(SGGeod::fromDegM(i->getLongitude(),
i->getLatitude(),
i->getAltitude()));
SGGeod other = i->getPos();
SGGeodesy::inverse(curr, other, course, az2, dist);
bearing = fabs(heading - course);
if (bearing > 180)
@ -350,9 +308,7 @@ void FGGroundController::checkSpeedAdjustment(int id, double lat,
towerController->getActiveTraffic().begin();
i != towerController->getActiveTraffic().end(); i++) {
SG_LOG(SG_ATC, SG_BULK, "Comparing " << current->getId() << " and " << i->getId());
SGGeod other(SGGeod::fromDegM(i->getLongitude(),
i->getLatitude(),
i->getAltitude()));
SGGeod other = i->getPos();
SGGeodesy::inverse(curr, other, course, az2, dist);
bearing = fabs(heading - course);
if (bearing > 180)
@ -447,7 +403,7 @@ void FGGroundController::checkHoldPosition(int id, double lat,
double lon, double heading,
double speed, double alt)
{
FGGroundNetwork* network = dynamics->parent()->groundNetwork();
FGGroundNetwork* network = parent->parent()->groundNetwork();
TrafficVectorIterator current;
TrafficVectorIterator i = activeTraffic.begin();
if (activeTraffic.size()) {
@ -499,7 +455,7 @@ void FGGroundController::checkHoldPosition(int id, double lat,
//if (tx->hasBlock(now) || nx->hasBlock(now) ) {
// current->setHoldPosition(true);
//}
SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
SGGeod start = i->getPos();
SGGeod end (nx->getStart()->geod());
double distance = SGGeodesy::distanceM(start, end);
@ -530,11 +486,11 @@ void FGGroundController::checkHoldPosition(int id, double lat,
if ((origStatus != currStatus) && available) {
SG_LOG(SG_ATC, SG_DEBUG, "Issuing hold short instruction " << currStatus << " " << available);
if (currStatus == true) { // No has a hold short instruction
transmit(&(*current), dynamics, MSG_HOLD_POSITION, ATC_GROUND_TO_AIR, true);
transmit(&(*current), parent, MSG_HOLD_POSITION, ATC_GROUND_TO_AIR, true);
SG_LOG(SG_ATC, SG_DEBUG, "Transmitting hold short instruction " << currStatus << " " << available);
current->setState(1);
} else {
transmit(&(*current), dynamics, MSG_RESUME_TAXI, ATC_GROUND_TO_AIR, true);
transmit(&(*current), parent, MSG_RESUME_TAXI, ATC_GROUND_TO_AIR, true);
SG_LOG(SG_ATC, SG_DEBUG, "Transmitting resume instruction " << currStatus << " " << available);
current->setState(2);
}
@ -668,35 +624,6 @@ bool FGGroundController::checkForCircularWaits(int id)
}
}
// Note that this function is probably obsolete...
bool FGGroundController::hasInstruction(int id)
{
// Search the activeTraffic vector to find a traffic vector with our id
TrafficVectorIterator i = searchActiveTraffic(id);
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
SG_LOG(SG_GENERAL, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
return false;
}
FGATCInstruction FGGroundController::getInstruction(int id)
{
// Search the activeTraffic vector to find a traffic vector with our id
TrafficVectorIterator i = searchActiveTraffic(id);
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
SG_LOG(SG_GENERAL, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
return FGATCInstruction();
}
// Note that this function is copied from simgear. for maintanance purposes, it's probabtl better to make a general function out of that.
static void WorldCoordinate(osg::Matrix& obj_pos, double lat,
double lon, double elev, double hdg, double slope)
@ -715,7 +642,7 @@ static void WorldCoordinate(osg::Matrix& obj_pos, double lat,
void FGGroundController::render(bool visible)
{
SGMaterialLib *matlib = globals->get_matlib();
FGGroundNetwork* network = dynamics->parent()->groundNetwork();
FGGroundNetwork* network = parent->parent()->groundNetwork();
if (group) {
//int nr = ;
@ -745,7 +672,7 @@ void FGGroundController::render(bool visible)
const int pos = i->getCurrentPosition();
if (pos > 0) {
FGTaxiSegment* segment = network->findSegment(pos);
SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
SGGeod start = i->getPos();
SGGeod end (segment->getEnd()->geod());
double length = SGGeodesy::distanceM(start, end);
@ -903,17 +830,17 @@ void FGGroundController::render(bool visible)
}
string FGGroundController::getName() {
return string(parent->getId() + "-ground");
return string(parent->parent()->getName() + "-ground");
}
void FGGroundController::update(double dt)
{
time_t now = globals->get_time_params()->get_cur_time();
FGGroundNetwork* network = dynamics->parent()->groundNetwork();
FGGroundNetwork* network = parent->parent()->groundNetwork();
network->unblockAllSegments(now);
int priority = 1;
TrafficVector& startupTraffic(dynamics->getStartupController()->getActiveTraffic());
TrafficVector& startupTraffic(parent->getStartupController()->getActiveTraffic());
TrafficVectorIterator i;
//sort(activeTraffic.begin(), activeTraffic.end(), compare_trafficrecords);
@ -927,8 +854,9 @@ void FGGroundController::update(double dt)
updateActiveTraffic(i, priority, now);
}
FGATCController::eraseDeadTraffic(startupTraffic);
FGATCController::eraseDeadTraffic(activeTraffic);
//FIXME
//FGATCController::eraseDeadTraffic(startupTraffic);
FGATCController::eraseDeadTraffic();
}
void FGGroundController::updateStartupTraffic(TrafficVectorIterator i,
@ -953,7 +881,7 @@ void FGGroundController::updateStartupTraffic(TrafficVectorIterator i,
return;
}
FGGroundNetwork* network = dynamics->parent()->groundNetwork();
FGGroundNetwork* network = parent->parent()->groundNetwork();
if (!network) {
SG_LOG(SG_ATC, SG_ALERT, "updateStartupTraffic: missing ground network");
@ -1021,7 +949,7 @@ bool FGGroundController::updateActiveTraffic(TrafficVectorIterator i,
double length = 0;
double vTaxi = (i->getAircraft()->getPerformance()->vTaxi() * SG_NM_TO_METER) / 3600;
FGGroundNetwork* network = dynamics->parent()->groundNetwork();
FGGroundNetwork* network = parent->parent()->groundNetwork();
if (!network) {
SG_LOG(SG_ATC, SG_ALERT, "updateActiveTraffic: missing ground network");
@ -1063,3 +991,9 @@ bool FGGroundController::updateActiveTraffic(TrafficVectorIterator i,
return true;
}
int FGGroundController::getFrequency() {
int groundFreq = parent->getGroundFrequency(2);
int towerFreq = parent->getTowerFrequency(2);
return groundFreq>0?groundFreq:towerFreq;
}

View file

@ -32,7 +32,7 @@
class FGAirportDynamics;
/**************************************************************************************
* class FGGroundNetWork
* class FGGroundController
*************************************************************************************/
class FGGroundController : public FGATCController
{
@ -43,13 +43,9 @@ private:
int count;
int version;
TrafficVector activeTraffic;
TrafficVectorIterator currTraffic;
FGTowerController *towerController;
FGAirport *parent;
FGAirportDynamics* dynamics;
/**Returns the frequency to be used. */
int getFrequency();
void checkSpeedAdjustment(int id, double lat, double lon,
@ -61,13 +57,12 @@ private:
void updateStartupTraffic(TrafficVectorIterator i, int& priority, time_t now);
bool updateActiveTraffic(TrafficVectorIterator i, int& priority, time_t now);
public:
FGGroundController();
FGGroundController(FGAirportDynamics *par);
~FGGroundController();
void setVersion (int v) { version = v;};
int getVersion() { return version; };
void init(FGAirportDynamics* pr);
bool exists() {
return hasNetwork;
};
@ -76,14 +71,10 @@ public:
};
virtual TrafficVectorIterator searchActiveTraffic(int id);
virtual void announcePosition(int id, FGAIFlightPlan *intendedRoute, int currentRoute,
double lat, double lon, double hdg, double spd, double alt,
double radius, int leg, FGAIAircraft *aircraft);
virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon, double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id);
bool checkTransmissionState(int minState, int MaxState, TrafficVectorIterator i, time_t now, AtcMsgId msgId,
AtcMsgDir msgDir);

View file

@ -71,8 +71,6 @@ FGStartupController::FGStartupController(FGAirportDynamics *par):
FGStartupController::~FGStartupController()
{
_isDestroying = true;
clearTrafficControllers(activeTraffic);
}
void FGStartupController::announcePosition(int id,
@ -85,7 +83,7 @@ void FGStartupController::announcePosition(int id,
{
init();
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
// Add a new TrafficRecord if no one exsists for this aircraft.
if (i == activeTraffic.end() || activeTraffic.empty()) {
@ -96,7 +94,7 @@ void FGStartupController::announcePosition(int id,
rec.setRunway(intendedRoute->getRunway());
rec.setLeg(leg);
rec.setPositionAndIntentions(currentPosition, intendedRoute);
//rec.setCallSign(callsign);
rec.setCallsign(ref->getCallSign());
rec.setAircraft(ref);
rec.setHoldPosition(true);
activeTraffic.push_back(rec);
@ -107,59 +105,6 @@ void FGStartupController::announcePosition(int id,
}
}
// NOTE:
// IF WE MAKE TRAFFICRECORD A MEMBER OF THE BASE CLASS
// THE FOLLOWING THREE FUNCTIONS: SIGNOFF, HAS INSTRUCTION AND GETINSTRUCTION CAN
// BECOME DEVIRTUALIZED AND BE A MEMBER OF THE BASE ATCCONTROLLER CLASS
// WHICH WOULD SIMPLIFY CODE MAINTENANCE.
// Note that this function is probably obsolete
bool FGStartupController::hasInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: checking ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->hasInstruction();
}
return false;
}
FGATCInstruction FGStartupController::getInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: requesting ATC instruction for aircraft without traffic record at " << SG_ORIGIN);
} else {
return i->getInstruction();
}
return FGATCInstruction();
}
void FGStartupController::signOff(int id)
{
// ensure we don't modify activeTraffic during destruction
if (_isDestroying)
return;
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
} else {
SG_LOG(SG_ATC, SG_DEBUG, i->getAircraft()->getCallSign() << " signing off from startupcontroller");
i = activeTraffic.erase(i);
}
}
bool FGStartupController::checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId,
AtcMsgDir msgDir)
{
@ -198,7 +143,7 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
double dt)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
TrafficVectorIterator current, closest;
if (i == activeTraffic.end() || (activeTraffic.size() == 0)) {
@ -225,9 +170,10 @@ void FGStartupController::updateAircraftInformation(int id, double lat, double l
time_t startTime = i->getAircraft()->getTrafficRef()->getDepartureTime();
time_t now = globals->get_time_params()->get_cur_time();
SG_LOG(SG_ATC, SG_BULK, i->getAircraft()->getTrafficRef()->getCallSign()
<< " is scheduled to depart in " << startTime-now << " seconds. Available = " << available
<< " at parking " << getGateName(i->getAircraft()));
if ((startTime - now) > 0) {
SG_LOG(SG_ATC, SG_BULK, i->getAircraft()->getTrafficRef()->getCallSign() << " is scheduled to depart in " << startTime - now << " seconds. Available = " << available << " at parking " << getGateName(i->getAircraft()));
}
if ((now - lastTransmission) > 3 + (rand() % 15)) {
available = true;
@ -317,7 +263,7 @@ void FGStartupController::render(bool visible)
SG_LOG(SG_ATC, SG_BULK, "rendering for " << i->getAircraft()->getCallSign() << "pos = " << pos);
if (pos > 0) {
FGTaxiSegment *segment = groundNet->findSegment(pos);
SGGeod start(SGGeod::fromDeg((i->getLongitude()), (i->getLatitude())));
SGGeod start = i->getPos();
SGGeod end (segment->getEnd()->geod());
double length = SGGeodesy::distanceM(start, end);
@ -480,11 +426,17 @@ void FGStartupController::render(bool visible)
}
string FGStartupController::getName() {
return string(parent->getId() + "-startup");
return string(parent->parent()->getName() + "-Startup");
}
void FGStartupController::update(double dt)
{
FGATCController::eraseDeadTraffic(activeTraffic);
FGATCController::eraseDeadTraffic();
}
int FGStartupController::getFrequency() {
int groundFreq = parent->getGroundFrequency(2);
int towerFreq = parent->getTowerFrequency(2);
return groundFreq>0?groundFreq:towerFreq;
}

View file

@ -28,8 +28,7 @@
#include <osg/Shape>
#include <simgear/compiler.h>
// There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
@ -45,9 +44,8 @@
class FGStartupController : public FGATCController
{
private:
TrafficVector activeTraffic;
//ActiveRunwayVec activeRunways;
FGAirportDynamics *parent;
/**Returns the frequency to be used. */
int getFrequency();
public:
FGStartupController(FGAirportDynamics *parent);
@ -57,23 +55,13 @@ public:
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft);
virtual void signOff(int id);
virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
virtual std::string getName();
virtual void update(double dt);
bool hasActiveTraffic() {
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
// Hpoefully, we can move this function to the base class, but I need to verify what is needed for the other controllers before doing so.
bool checkTransmissionState(int st, time_t now, time_t startTime, TrafficVectorIterator i, AtcMsgId msgId,
AtcMsgDir msgDir);

View file

@ -72,8 +72,6 @@ FGTowerController::FGTowerController(FGAirportDynamics *par) :
FGTowerController::~FGTowerController()
{
_isDestroying = true;
clearTrafficControllers(activeTraffic);
}
//
@ -88,7 +86,7 @@ void FGTowerController::announcePosition(int id,
init();
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
// Add a new TrafficRecord if no one exsists for this aircraft.
if (i == activeTraffic.end() || (activeTraffic.empty())) {
@ -132,7 +130,7 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
double dt)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
setDt(getDt() + dt);
@ -186,9 +184,11 @@ void FGTowerController::updateAircraftInformation(int id, double lat, double lon
if (ac->getTakeOffStatus() == 1) {
// transmit takeoff clearance
ac->setTakeOffStatus(2);
transmit(&(*i), &(*parent), MSG_CLEARED_FOR_TAKEOFF, ATC_GROUND_TO_AIR, true);
i->setState(10);
}
}
//FIXME Make it an member of traffic record
if (current.getAircraft()->getTakeOffStatus() == 2) {
current.setHoldPosition(false);
} else {
@ -218,7 +218,7 @@ void FGTowerController::signOff(int id)
return;
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
if (i == activeTraffic.end() || (activeTraffic.empty())) {
SG_LOG(SG_ATC, SG_ALERT,
"AI error: Aircraft without traffic record is signing off from tower at " << SG_ORIGIN);
@ -240,8 +240,7 @@ void FGTowerController::signOff(int id)
}
i->getAircraft()->resetTakeOffStatus();
activeTraffic.erase(i);
SG_LOG(SG_ATC, SG_DEBUG, "Signing off from tower controller");
FGATCController::signOff(id);
}
// NOTE:
@ -253,7 +252,7 @@ void FGTowerController::signOff(int id)
bool FGTowerController::hasInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
@ -268,7 +267,7 @@ bool FGTowerController::hasInstruction(int id)
FGATCInstruction FGTowerController::getInstruction(int id)
{
// Search activeTraffic for a record matching our id
TrafficVectorIterator i = searchActiveTraffic(activeTraffic, id);
TrafficVectorIterator i = FGATCController::searchActiveTraffic(id);
if (i == activeTraffic.end() || activeTraffic.empty()) {
SG_LOG(SG_ATC, SG_ALERT,
@ -290,5 +289,10 @@ string FGTowerController::getName() {
void FGTowerController::update(double dt)
{
FGATCController::eraseDeadTraffic(activeTraffic);
FGATCController::eraseDeadTraffic();
}
int FGTowerController::getFrequency() {
int towerFreq = parent->getTowerFrequency(2);
return towerFreq;
}

View file

@ -28,8 +28,7 @@
#include <osg/Shape>
#include <simgear/compiler.h>
// There is probably a better include than sg_geodesy to get the SG_NM_TO_METER...
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/constants.h>
#include <simgear/debug/logstream.hxx>
#include <simgear/structure/SGReferenced.hxx>
#include <simgear/structure/SGSharedPtr.hxx>
@ -43,9 +42,9 @@
class FGTowerController : public FGATCController
{
private:
TrafficVector activeTraffic;
ActiveRunwayVec activeRunways;
FGAirportDynamics *parent;
/**Returns the frequency to be used. */
int getFrequency();
public:
FGTowerController(FGAirportDynamics *parent);
@ -55,21 +54,15 @@ public:
double lat, double lon,
double hdg, double spd, double alt, double radius, int leg,
FGAIAircraft *aircraft);
virtual void signOff(int id);
void signOff(int id);
bool hasInstruction(int id);
FGATCInstruction getInstruction(int id);
virtual void updateAircraftInformation(int id, double lat, double lon,
double heading, double speed, double alt, double dt);
virtual bool hasInstruction(int id);
virtual FGATCInstruction getInstruction(int id);
virtual void render(bool);
virtual std::string getName();
virtual void update(double dt);
bool hasActiveTraffic() {
return ! activeTraffic.empty();
};
TrafficVector &getActiveTraffic() {
return activeTraffic;
};
};
#endif

View file

@ -334,7 +334,7 @@ void FGATCManager::update ( double time ) {
}
#if 0
// Test code: Print how far we're progressing along the taxi route.
SG_LOG(SG_ATC, SG_DEBUG, "Size of waypoint cue " << size);
SG_LOG(SG_ATC, SG_DEBUG, "Size of waypoint queue " << size);
for (int i = 0; i < size; i++) {
int val = fp->getRouteIndex(i);
SG_LOG(SG_ATC, SG_BULK, fp->getWayPoint(i)->getName() << " ");

View file

@ -36,6 +36,7 @@
#include <simgear/scene/material/mat.hxx>
#include <simgear/scene/util/OsgMath.hxx>
#include <simgear/timing/sg_time.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <Scenery/scenery.hxx>
@ -252,7 +253,7 @@ FGTrafficRecord::FGTrafficRecord():
allowPushback(true),
priority(0),
timer(0),
latitude(0), longitude(0), heading(0), speed(0), altitude(0), radius(0)
heading(0), speed(0), altitude(0), radius(0)
{
}
@ -289,12 +290,27 @@ void FGTrafficRecord::setAircraft(FGAIAircraft *ref)
aircraft = ref;
}
FGAIAircraft* FGTrafficRecord::getAircraft() const
{
return aircraft.ptr();
}
bool FGTrafficRecord::isDead() const {
if (!aircraft) {
return true;
}
return aircraft->getDie();
}
/*
void FGTrafficRecord::clearATCController() const {
if (aircraft) {
aircraft->clearATCController();
}
}
FGAIAircraft* FGTrafficRecord::getAircraft() const
{
if(aircraft.valid()) {
return aircraft.ptr();
}
return 0;
}
/**
* Check if another aircraft is ahead of the current one, and on the same taxiway
* @return true / false if this is/isn't the case.
*/
@ -339,8 +355,7 @@ void FGTrafficRecord::setPositionAndHeading(double lat, double lon,
double hdg, double spd,
double alt)
{
latitude = lat;
longitude = lon;
this->pos = SGGeod::fromDegFt(lon, lat, alt);
heading = hdg;
speed = spd;
altitude = alt;

View file

@ -142,6 +142,7 @@ public:
/**************************************************************************************
* class FGTrafficRecord
* Represents the interaction of an AI Aircraft and ATC
*************************************************************************************/
class FGTrafficRecord
{
@ -158,7 +159,9 @@ private:
time_t timer;
intVec intentions;
FGATCInstruction instruction;
double latitude, longitude, heading, speed, altitude, radius;
SGGeod pos;
double heading, speed, altitude, radius;
std::string callsign;
std::string runway;
SGSharedPtr<FGAIAircraft> aircraft;
@ -192,7 +195,7 @@ public:
FGATCInstruction getInstruction() const {
return instruction;
};
bool hasInstruction() {
bool hasInstruction() const {
return instruction.hasInstruction();
};
void setPositionAndHeading(double lat, double lon, double hdg, double spd, double alt);
@ -201,6 +204,8 @@ public:
bool isOpposing (FGGroundNetwork *, FGTrafficRecord &other, int node);
bool isActive(int margin) const;
bool isDead() const;
void clearATCController() const;
bool onRoute(FGGroundNetwork *, FGTrafficRecord &other);
@ -208,19 +213,16 @@ public:
return instruction.getChangeSpeed();
};
double getLatitude () const {
return latitude ;
};
double getLongitude() const {
return longitude;
};
SGGeod getPos() {
return pos;
}
double getHeading () const {
return heading ;
};
double getSpeed () const {
return speed ;
};
double getAltitude () const {
double getFAltitude () const {
return altitude ;
};
double getRadius () const {
@ -261,10 +263,15 @@ public:
instruction.setResolveCircularWait(false);
};
void setCallsign(std::string clsgn) { callsign = clsgn; };
const std::string& getCallsign() const {
return callsign;
};
const std::string& getRunway() const {
return runway;
};
//void setCallSign(string clsgn) { callsign = clsgn; };
void setAircraft(FGAIAircraft *ref);
void updateState() {

View file

@ -215,6 +215,7 @@ FGAirportDynamics::FGAirportDynamics(FGAirport * ap):
startupController (this),
towerController (this),
approachController (this),
groundController (this),
atisSequenceIndex(-1),
atisSequenceTimeStamp(0.0)
@ -232,7 +233,7 @@ FGAirportDynamics::~FGAirportDynamics()
void FGAirportDynamics::init()
{
groundController.setTowerController(&towerController);
groundController.init(this);
groundController.init();
}
FGParking* FGAirportDynamics::innerGetAvailableParking(double radius, const string & flType,
@ -887,6 +888,34 @@ const string FGAirportDynamics::getId() const
// so that at least I can start working on assigning different frequencies to different
// operations.
int FGAirportDynamics::getApproachFrequency(unsigned nr)
{
int approachFreq = 0;
if (nr < 2) {
SG_LOG(SG_ATC, SG_ALERT,
"Leg value is smaller than two at " << SG_ORIGIN);
}
const intVec& freqApproach(parent()->groundNetwork()->getApproachFrequencies());
if (freqApproach.size() == 0) {
return 0;
}
if ((freqApproach.size() > nr - 1) && (nr > 1)) {
approachFreq = freqApproach[nr - 1];
}
if ((freqApproach.size() < nr - 1) && (nr > 1)) {
approachFreq =
(freqApproach.size() <
(nr - 1)) ? freqApproach[freqApproach.size() -
1] : freqApproach[nr - 2];
}
if ((freqApproach.size() >= nr - 1) && (nr > 1)) {
approachFreq = freqApproach[nr - 2];
}
return approachFreq;
}
int FGAirportDynamics::getGroundFrequency(unsigned leg)
{
//return freqGround.size() ? freqGround[0] : 0; };

View file

@ -167,6 +167,7 @@ public:
return &approachController;
};
int getApproachFrequency (unsigned nr);
int getGroundFrequency(unsigned leg);
int getTowerFrequency (unsigned nr);

View file

@ -564,7 +564,10 @@ FGTaxiSegment* FGGroundNetwork::findSegmentByHeading(const FGTaxiNode* from, con
return best; // not found
}
const intVec& FGGroundNetwork::getApproachFrequencies() const
{
return freqApproach;
}
const intVec& FGGroundNetwork::getTowerFrequencies() const
{

View file

@ -284,6 +284,7 @@ public:
void addVersion(int v) {version = v; };
void unblockAllSegments(time_t now);
const intVec& getApproachFrequencies() const;
const intVec& getTowerFrequencies() const;
const intVec& getGroundFrequencies() const;

View file

@ -28,6 +28,6 @@
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIFlightPlanTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(AIManagerTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(GroundnetTests, "Unit tests");
// CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficTests, "Unit tests");
// CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(TrafficMgrTests, "Unit tests");
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(SubmodelsTests, "Unit tests");

View file

@ -73,6 +73,8 @@ void TrafficTests::setUp()
fgSetBool("/environment/realwx/enabled", false);
fgSetBool("/environment/metar/valid", false);
fgSetBool("/sim/terrasync/ai-data-update-now", false);
fgSetBool("/sim/sound/atc/enabled", true);
fgSetDouble("/instrumentation/comm[0]/frequencies/selected-mhz", 121.70);
globals->append_data_path(SGPath::fromUtf8(FG_TEST_SUITE_DATA), false);