refs #262, fix update of aircraft position

Described here (3): https://dev.vatsim-germany.org/boards/22/topics/1792?r=1801#message-1801

* Also renamed: setOwnAircraftAvionics -> setOwnCockpit to be consistent
* Removed outdated methods
This commit is contained in:
Klaus Basan
2014-06-09 01:33:19 +02:00
parent 8c792a61e3
commit dac556c6e9
18 changed files with 156 additions and 164 deletions

View File

@@ -40,9 +40,6 @@ namespace BlackCore
// 1. Init by "network driver"
this->m_network = new CNetworkVatlib(this);
// 2. Init own aircraft
this->initOwnAircraft();
// 3. Init VATSIM bookings
this->m_vatsimBookingReader = new CVatsimBookingReader(this->getRuntime()->getIContextSettings()->getNetworkSettings().getBookingServiceUrl(), this);
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CContextNetwork::psReceivedBookings);
@@ -89,31 +86,6 @@ namespace BlackCore
if (this->isConnected()) this->disconnectFromNetwork();
}
/*
* Init own aircraft
*/
void CContextNetwork::initOwnAircraft()
{
Q_ASSERT(this->getRuntime());
Q_ASSERT(this->getRuntime()->getIContextSettings());
this->ownAircraft().initComSystems();
this->ownAircraft().initTransponder();
CAircraftSituation situation(
CCoordinateGeodetic(
CLatitude::fromWgs84("N 049° 18' 17"),
CLongitude::fromWgs84("E 008° 27' 05"),
CLength(0, CLengthUnit::m())),
CAltitude(312, CAltitude::MeanSeaLevel, CLengthUnit::ft())
);
this->ownAircraft().setSituation(situation);
this->ownAircraft().setPilot(this->getIContextSettings()->getNetworkSettings().getCurrentTrafficNetworkServer().getUser());
// TODO: This would need to come from somewhere (mappings)
// Own callsign, plane ICAO status, model used
this->ownAircraft().setCallsign(CCallsign("BLACK"));
this->ownAircraft().setIcaoInfo(CAircraftIcao("C172", "L1P", "GA", "GA", "0000ff"));
}
/*
* Connect to network
*/
@@ -141,12 +113,13 @@ namespace BlackCore
if (CNetworkUtils::canConnect(currentServer, msg, 2000))
{
INetwork::LoginMode mode = static_cast<INetwork::LoginMode>(loginMode);
this->ownAircraft().setPilot(currentServer.getUser()); // still needed?
this->getIContextOwnAircraft()->updatePilot(currentServer.getUser(), this->getPathAndContextId());
const CAircraft ownAircraft = this->ownAircraft();
this->m_network->presetServer(currentServer);
this->m_network->presetLoginMode(mode);
this->m_network->presetCallsign(this->ownAircraft().getCallsign());
this->m_network->presetIcaoCodes(this->ownAircraft().getIcaoInfo());
this->m_network->setOwnAircraft(this->ownAircraft());
this->m_network->presetCallsign(ownAircraft.getCallsign());
this->m_network->presetIcaoCodes(ownAircraft.getIcaoInfo());
this->m_network->setOwnAircraft(ownAircraft);
this->m_network->initiateConnection();
msg = "Connection pending ";
msg.append(" ").append(currentServer.getAddress()).append(" ").append(QString::number(currentServer.getPort()));
@@ -194,72 +167,6 @@ namespace BlackCore
return this->m_network->isConnected();
}
/*
* Own Aircraft
*/
CStatusMessageList CContextNetwork::setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft)
{
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, aircraft.toQString());
CStatusMessageList msgs;
if (this->m_network->isConnected())
{
msgs.push_back(CStatusMessage(CStatusMessage::TypeTrafficNetwork, CStatusMessage::SeverityError, "Cannot set aircraft info, network already connected"));
}
else
{
this->ownAircraft() = aircraft;
}
return msgs;
}
/*
* Own position
*/
void CContextNetwork::updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude)
{
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, position.toQString(), altitude.toQString());
this->ownAircraft().setPosition(position);
this->ownAircraft().setAltitude(altitude);
this->m_network->setOwnAircraftPosition(position, altitude);
}
/*
* Update own situation
*/
void CContextNetwork::updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation)
{
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, situation.toQString());
this->ownAircraft().setSituation(situation);
this->m_network->setOwnAircraftSituation(situation);
}
/*
* Own cockpit data
*/
void CContextNetwork::updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder)
{
if (this->getRuntime()->isSlotLogForNetworkEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, com1.toQString(), com2.toQString(), transponder.toQString());
bool changed = false;
if (com1 != this->ownAircraft().getCom1System())
{
this->ownAircraft().setCom1System(com1);
changed = true;
}
if (com2 != this->ownAircraft().getCom2System())
{
this->ownAircraft().setCom2System(com2);
changed = true;
}
if (transponder != this->ownAircraft().getTransponder())
{
this->ownAircraft().setTransponder(transponder);
changed = true;
}
if (!changed) return;
this->m_network->setOwnAircraftAvionics(com1, com2, transponder);
}
/*
* Send text messages
*/
@@ -602,11 +509,11 @@ namespace BlackCore
return this->getRuntime()->getCContextOwnAircraft()->ownAircraft();
}
CAircraft &CContextNetwork::ownAircraft()
void CContextNetwork::psChangedOwnAircraft(const CAircraft &aircraft, const QString &originator)
{
Q_ASSERT(this->getRuntime());
Q_ASSERT(this->getRuntime()->getCContextOwnAircraft());
return this->getRuntime()->getCContextOwnAircraft()->ownAircraft();
Q_ASSERT(this->m_network);
Q_UNUSED(originator);
this->m_network->setOwnAircraft(aircraft);
}
} // namespace

View File

@@ -35,22 +35,6 @@ namespace BlackCore
//! Destructor
virtual ~CContextNetwork();
/*!
* Set own aircraft
* \param aircraft
* \return message list, as aircraft can only be set prior connecting
*/
BlackMisc::CStatusMessageList setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft);
//! Own position, be aware height is terrain height
void updateOwnPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude);
//! Complete situation update
void updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation);
//! Update own cockpit
void updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder);
public slots: // IContextNetwork overrides
//! \copydoc IContextNetwork::readAtcBookingsFromSource()
@@ -163,9 +147,6 @@ namespace BlackCore
//! ATC list, with booked controllers
BlackMisc::Aviation::CAtcStationList &atcStationsBooked() { return m_atcStationsBooked; }
//! Init my very own aircraft
void initOwnAircraft();
//! Get network settings
BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const
{
@@ -186,10 +167,10 @@ namespace BlackCore
//! Own aircraft
const BlackMisc::Aviation::CAircraft &ownAircraft() const;
//! Own aircraft
BlackMisc::Aviation::CAircraft &ownAircraft();
private slots:
//! Own aircraft was updated
void psChangedOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator);
//! ATC bookings received
void psReceivedBookings(const BlackMisc::Aviation::CAtcStationList &bookedStations);

View File

@@ -37,10 +37,17 @@ namespace BlackCore
return s;
}
//! \copydoc CContext::getPathAndContextId()
virtual QString getPathAndContextId() const { return this->buildPathAndContextId(ObjectPath()); }
//! Destructor
virtual ~IContextOwnAircraft() {}
signals:
//! Aircraft changed
//! \remarks local only
void changedAircraft(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator);
//! Aircraft situation update
//! \remarks local only
void changedAircraftSituation(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator);
@@ -50,6 +57,7 @@ namespace BlackCore
void changedAircraftPosition(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator);
//! Aircraft cockpit update
//! \remarks DBus and local
void changedAircraftCockpit(const BlackMisc::Aviation::CAircraft &aircraft, const QString &originator);
public slots:
@@ -69,6 +77,9 @@ namespace BlackCore
//! Update own cockpit
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) = 0;
//! Set current pilot
virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) = 0;
//! Output volumens, volumes 0..100
virtual void setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) = 0;

View File

@@ -99,13 +99,22 @@ namespace BlackCore
// trigger the correct signals
bool changedCockpit = this->updateOwnCockpit(aircraft.getCom1System(), aircraft.getCom2System(), aircraft.getTransponder(), originator);
this->updateOwnPosition(aircraft.getPosition(), aircraft.getAltitude() , originator);
this->updateOwnSituation(aircraft.getSituation(), originator);
bool changedPosition = this->updateOwnPosition(aircraft.getPosition(), aircraft.getAltitude() , originator);
bool changedSituation = this->updateOwnSituation(aircraft.getSituation(), originator);
bool changed = changedCockpit || changedPosition || changedSituation;
// new voice rooms, cockpit has changed
if (changedCockpit) this->resolveVoiceRooms();
// all the rest
this->m_ownAircraft = aircraft;
// any change triggers a global updated aircraft signal
// comparison is not to avoid setting the value, but avoid wrong signals
if (changed || this->m_ownAircraft != aircraft)
{
emit this->changedAircraft(aircraft, originator);
// now set value
this->m_ownAircraft = aircraft;
}
}
/*
@@ -123,7 +132,11 @@ namespace BlackCore
this->m_ownAircraft.setAltitude(altitude);
}
if (changed) emit this->changedAircraftPosition(this->m_ownAircraft, originator);
if (changed)
{
emit this->changedAircraftPosition(this->m_ownAircraft, originator);
emit this->changedAircraft(this->m_ownAircraft, originator);
}
return changed;
}
@@ -136,8 +149,12 @@ namespace BlackCore
bool changed = this->m_ownAircraft.getSituation() == situation;
if (!changed) return changed;
this->m_ownAircraft.setSituation(situation);
emit this->changedAircraftSituation(this->m_ownAircraft, originator);
if (changed)
{
this->m_ownAircraft.setSituation(situation);
emit this->changedAircraftSituation(this->m_ownAircraft, originator);
emit this->changedAircraft(this->m_ownAircraft, originator);
}
return changed;
}
@@ -147,30 +164,25 @@ namespace BlackCore
bool CContextOwnAircraft::updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator)
{
if (this->getRuntime()->isSlotLogForOwnAircraftEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, com1.toQString(), com2.toQString(), transponder.toQString());
bool changed = false;
if (com1 != this->m_ownAircraft.getCom1System())
{
this->m_ownAircraft.setCom1System(com1);
changed = true;
}
if (com2 != this->m_ownAircraft.getCom2System())
{
this->m_ownAircraft.setCom2System(com2);
changed = true;
}
if (transponder != this->m_ownAircraft.getTransponder())
{
this->m_ownAircraft.setTransponder(transponder);
changed = true;
}
bool changed = this->m_ownAircraft.hasChangedCockpitData(com1, com2, transponder);
if (changed)
{
this->m_ownAircraft.setCockpit(com1, com2, transponder);
emit this->changedAircraftCockpit(this->m_ownAircraft, originator);
emit this->changedAircraft(this->m_ownAircraft, originator);
this->resolveVoiceRooms();
}
return changed;
}
bool CContextOwnAircraft::updatePilot(const CUser &pilot, const QString &originator)
{
if (this->m_ownAircraft.getPilot() == pilot) return false;
this->m_ownAircraft.setPilot(pilot);
emit this->changedAircraft(this->m_ownAircraft, originator);
return true;
}
void CContextOwnAircraft::setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2)
{
if (this->getRuntime()->isSlotLogForOwnAircraftEnabled()) this->getRuntime()->logSlot(Q_FUNC_INFO, QString::number(outputVolumeCom1), QString::number(outputVolumeCom2));

View File

@@ -48,6 +48,9 @@ namespace BlackCore
//! \copydoc IContextOwnAircraft::updateOwnCockpit()
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updatePilot()
virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override;
//! \copydoc IContextOwnAircraft::setAudioOutputVolumes
virtual void setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) override;
@@ -80,7 +83,7 @@ namespace BlackCore
QString m_voiceRoom1UrlOverride; //!< overridden voice room url
QString m_voiceRoom2UrlOverride; //!< overridden voice room url
//! Init my very own aircraft
//! Init my very own aircraft with some defaults, before overridden by simulator
void initOwnAircraft();
//! Resolve voice rooms

View File

@@ -58,6 +58,11 @@ namespace BlackCore
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updateOwnCockpit"), com1, com2, transponder, originator);
}
bool CContextOwnAircraftProxy::updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator)
{
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updatePilot"), pilot, originator);
}
void CContextOwnAircraftProxy::setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2)
{
this->m_dBusInterface->callDBus(QLatin1Literal("updateOwnCockpitOutputVolumes"), outputVolumeCom1, outputVolumeCom2);

View File

@@ -52,7 +52,10 @@ namespace BlackCore
virtual bool updateOwnSituation(const BlackMisc::Aviation::CAircraftSituation &situation, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updateOwnCockpit()
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originato4) override;
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updatePilot()
virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override;
//! \copydoc IContextOwnAircraft::setAudioOutputVolumes
virtual void setAudioOutputVolumes(int outputVolumeCom1, int outputVolumeCom2) override;

View File

@@ -472,6 +472,11 @@ namespace BlackCore
c = this->connect(this->m_contextNetwork, &IContextNetwork::changedAtcStationOnlineConnectionStatus,
this->getCContextOwnAircraft(), &CContextOwnAircraft::changedAtcStationOnlineConnectionStatus);
Q_ASSERT(c);
// inject updated own aircraft to network
c = this->connect(this->m_contextOwnAircraft, &IContextOwnAircraft::changedAircraft,
this->getCContextNetwork(), &CContextNetwork::psChangedOwnAircraft);
Q_ASSERT(c);
}
}
@@ -647,6 +652,20 @@ namespace BlackCore
return static_cast<CContextApplication *>(this->m_contextApplication);
}
CContextNetwork *CRuntime::getCContextNetwork()
{
Q_ASSERT_X(!this->m_contextApplication || this->m_contextNetwork->usingLocalObjects(), "CCoreRuntime", "Cannot downcast to local object");
return static_cast<CContextNetwork *>(this->m_contextNetwork);
}
const CContextNetwork *CRuntime::getCContextNetwork() const
{
Q_ASSERT_X(!this->m_contextApplication || this->m_contextNetwork->usingLocalObjects(), "CCoreRuntime", "Cannot downcast to local object");
return static_cast<CContextNetwork *>(this->m_contextNetwork);
}
CContextOwnAircraft *CRuntime::getCContextOwnAircraft()
{
Q_ASSERT_X(!this->m_contextOwnAircraft || this->m_contextOwnAircraft->usingLocalObjects(), "CCoreRuntime", "Cannot downcast to local object");

View File

@@ -176,6 +176,14 @@ namespace BlackCore
//! \remarks only applicable for local object
const CContextOwnAircraft *getCContextOwnAircraft() const;
//! Context for network
//! \remarks only applicable for local object
CContextNetwork *getCContextNetwork();
//! Context for network
//! \remarks only applicable for local object
const CContextNetwork *getCContextNetwork() const;
//! Context for simulator
//! \remarks only applicable for local object
CContextSimulator *getCContextSimulator();

View File

@@ -124,12 +124,16 @@ namespace BlackCore
void CContextSimulator::updateOwnAircraft()
{
Q_ASSERT(this->getIContextOwnAircraft());
CAircraft aircraft = m_simulator->getOwnAircraft();
// the methods will check, if an update is really required
// we make sure not to override values we do not have
CAircraft aircraft = this->getIContextOwnAircraft()->getOwnAircraft();
CAircraft simulatorAircraft = this->m_simulator->getOwnAircraft();
aircraft.setSituation(simulatorAircraft.getSituation());
aircraft.setCockpit(simulatorAircraft.getCom1System(), simulatorAircraft.getCom2System(), simulatorAircraft.getTransponderCode());
// the method will check, if an update is really required
// these are local (non DBus) calls
this->getIContextOwnAircraft()->updateOwnSituation(aircraft.getSituation(), IContextSimulator::InterfaceName());
this->getIContextOwnAircraft()->updateOwnCockpit(aircraft.getCom1System(), aircraft.getCom2System(), aircraft.getTransponder(), IContextSimulator::InterfaceName());
this->getIContextOwnAircraft()->updateOwnAircraft(aircraft, this->getPathAndContextId());
}
void CContextSimulator::addAircraftSituation(const CCallsign &callsign, const CAircraftSituation &initialSituation)

View File

@@ -295,19 +295,22 @@ namespace BlackCore
/*!
* Set the position and altitude of our own aircraft.
* \deprecated No longer needed with own aircraft context, only used in client sample
*/
virtual void setOwnAircraftPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) = 0;
/*!
* Set the position, altitude, orientation, and miscellaneous state of our own aircraft.
* \deprecated No longer needed with own aircraft context, only used in client sample
*/
virtual void setOwnAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) = 0;
/*!
* Set the COM frequencies and transponder code and mode of our own aircraft.
* \deprecated No longer needed with own aircraft context, only used in client sample
*/
virtual void setOwnAircraftAvionics(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2,
const BlackMisc::Aviation::CTransponder &transponder) = 0;
virtual void setOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2,
const BlackMisc::Aviation::CTransponder &transponder) = 0;
//! @}
////////////////////////////////////////////////////////////////

View File

@@ -496,7 +496,7 @@ namespace BlackCore
m_ownAircraft.setSituation(situation);
}
void CNetworkVatlib::setOwnAircraftAvionics(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2,
void CNetworkVatlib::setOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2,
const BlackMisc::Aviation::CTransponder &xpdr)
{
m_ownAircraft.setCom1System(com1);

View File

@@ -70,7 +70,7 @@ namespace BlackCore
virtual void setOwnAircraft(const BlackMisc::Aviation::CAircraft &aircraft) override;
virtual void setOwnAircraftPosition(const BlackMisc::Geo::CCoordinateGeodetic &position, const BlackMisc::Aviation::CAltitude &altitude) override;
virtual void setOwnAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
virtual void setOwnAircraftAvionics(const BlackMisc::Aviation::CComSystem &com1,
virtual void setOwnCockpit(const BlackMisc::Aviation::CComSystem &com1,
const BlackMisc::Aviation::CComSystem &com2,
const BlackMisc::Aviation::CTransponder &xpdr) override;