mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
refs #246 refactored FSIPI(R) custom packet encode/decode into INetwork
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
#include "airspace_monitor.h"
|
||||
#include "blackmisc/project.h"
|
||||
#include "blackmisc/indexvariantmap.h"
|
||||
#include "network_vatlib.h" // for createFsipiCustomPacketData
|
||||
|
||||
namespace BlackCore
|
||||
{
|
||||
@@ -33,7 +32,7 @@ namespace BlackCore
|
||||
this->connect(this->m_network, &INetwork::aircraftPositionUpdate, this, &CAirspaceMonitor::aircraftUpdateReceived);
|
||||
this->connect(this->m_network, &INetwork::frequencyReplyReceived, this, &CAirspaceMonitor::frequencyReceived);
|
||||
this->connect(this->m_network, &INetwork::capabilitiesReplyReceived, this, &CAirspaceMonitor::capabilitiesReplyReceived);
|
||||
this->connect(this->m_network, &INetwork::customPacketReceived, this, &CAirspaceMonitor::customPacketReceived);
|
||||
this->connect(this->m_network, &INetwork::fsipirCustomPacketReceived, this, &CAirspaceMonitor::fsipirCustomPacketReceived);
|
||||
this->connect(this->m_network, &INetwork::serverReplyReceived, this, &CAirspaceMonitor::serverReplyReceived);
|
||||
|
||||
this->connect(this->m_vatsimBookingReader, &CVatsimBookingReader::dataRead, this, &CAirspaceMonitor::receivedBookings);
|
||||
@@ -237,25 +236,20 @@ namespace BlackCore
|
||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::customPacketReceived(const CCallsign &callsign, const QString &packet, const QStringList &data)
|
||||
void CAirspaceMonitor::fsipirCustomPacketReceived(const CCallsign &callsign, const QString &, const QString &, const QString &, const QString &model)
|
||||
{
|
||||
if (callsign.isEmpty() || data.isEmpty()) return;
|
||||
if (packet.startsWith("FSIPIR", Qt::CaseInsensitive))
|
||||
if (callsign.isEmpty() || model.isEmpty()) return;
|
||||
|
||||
// Request of other client, I can get the other's model from that
|
||||
CIndexVariantMap vm(CClient::IndexQueriedModelString, QVariant(model));
|
||||
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
|
||||
{
|
||||
// Request of other client, I can get the other's model from that
|
||||
// FsInn response is usually my model
|
||||
QString model = data.last();
|
||||
if (model.isEmpty()) return;
|
||||
CIndexVariantMap vm(CClient::IndexQueriedModelString, QVariant(model));
|
||||
if (!this->m_otherClients.contains(&CClient::getCallsign, callsign))
|
||||
{
|
||||
// with custom packets it can happen,
|
||||
//the packet is received before any other packet
|
||||
this->m_otherClients.push_back(CClient(callsign));
|
||||
}
|
||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||
this->sendFsipiCustomPacket(callsign); // response
|
||||
// with custom packets it can happen,
|
||||
//the packet is received before any other packet
|
||||
this->m_otherClients.push_back(CClient(callsign));
|
||||
}
|
||||
this->m_otherClients.applyIf(&CClient::getCallsign, callsign, vm);
|
||||
this->sendFsipiCustomPacket(callsign); // response
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::serverReplyReceived(const CCallsign &callsign, const QString &server)
|
||||
@@ -291,17 +285,19 @@ namespace BlackCore
|
||||
|
||||
void CAirspaceMonitor::sendFsipiCustomPacket(const CCallsign &recipientCallsign) const
|
||||
{
|
||||
QStringList data = this->createFsipiCustomPacketData();
|
||||
this->m_network->sendCustomPacket(recipientCallsign.asString(), "FSIPI", data);
|
||||
CAircraft me = this->m_ownAircraft;
|
||||
CAircraftIcao icao = me.getIcaoInfo();
|
||||
QString modelString;
|
||||
// FIXME (MS) simulator or ownaircraft context should send an ownAircraftModelChanged signal, so we wouldn't need to interrogate the simulator context here.
|
||||
//if (this->getIContextSimulator())
|
||||
//{
|
||||
// if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString();
|
||||
//}
|
||||
if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion();
|
||||
this->m_network->sendFsipiCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString);
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::sendFsipirCustomPacket(const CCallsign &recipientCallsign) const
|
||||
{
|
||||
QStringList data = this->createFsipiCustomPacketData();
|
||||
this->m_network->sendCustomPacket(recipientCallsign.asString(), "FSIPIR", data);
|
||||
}
|
||||
|
||||
QStringList CAirspaceMonitor::createFsipiCustomPacketData() const
|
||||
{
|
||||
CAircraft me = this->m_ownAircraft;
|
||||
CAircraftIcao icao = me.getIcaoInfo();
|
||||
@@ -312,11 +308,7 @@ namespace BlackCore
|
||||
// if (this->getIContextSimulator()->isConnected()) modelString = this->getIContextSimulator()->getOwnAircraftModel().getQueriedModelString();
|
||||
//}
|
||||
if (modelString.isEmpty()) modelString = CProject::systemNameAndVersion();
|
||||
QStringList data = CNetworkVatlib::createFsipiCustomPacketData(
|
||||
"0", icao.getAirlineDesignator(), icao.getAircraftDesignator(),
|
||||
"", "", "", "",
|
||||
icao.getAircraftCombinedType(), modelString);
|
||||
return data;
|
||||
this->m_network->sendFsipirCustomPacket(recipientCallsign, icao.getAirlineDesignator(), icao.getAircraftDesignator(), icao.getAircraftCombinedType(), modelString);
|
||||
}
|
||||
|
||||
void CAirspaceMonitor::receivedBookings(const CAtcStationList &bookedStations)
|
||||
|
||||
@@ -125,7 +125,7 @@ namespace BlackCore
|
||||
private slots:
|
||||
void realNameReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &realname);
|
||||
void capabilitiesReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, quint32 flags);
|
||||
void customPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &packet, const QStringList &data);
|
||||
void fsipirCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &, const QString &, const QString &, const QString &model);
|
||||
void serverReplyReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &server);
|
||||
void metarReceived(const QString &metarMessage);
|
||||
void flightplanReceived(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CFlightPlan &flightPlan);
|
||||
|
||||
@@ -212,12 +212,41 @@ namespace BlackCore
|
||||
*/
|
||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) = 0;
|
||||
|
||||
//! @}
|
||||
////////////////////////////////////////////////////////////////
|
||||
//! \name Custom packets
|
||||
//! @{
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
/*!
|
||||
* Send a custom packet.
|
||||
* \pre Network must be connected when calling this function.
|
||||
* \deprecated As a short cut you can use this slot directly, but it is better to implement the encoding in INetwork and add a new signal.
|
||||
*/
|
||||
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) = 0;
|
||||
|
||||
/*!
|
||||
* Send an FSInn custom packet.
|
||||
* \details FSIPI(R) queries
|
||||
* <BLOCKQUOTE>
|
||||
* index 0 .. 0/1 ???
|
||||
* 1 .. MQT, GEC, DLH -> Airline ICAO, most of the time empty
|
||||
* 2 .. AIRCRAFT ICAO "B747"
|
||||
* 3 .. 10.64195
|
||||
* 4 .. 1.06080:
|
||||
* 5 .. 5825.00000
|
||||
* 6 .. 4.DD89CCB6.EC9BB7D7
|
||||
* 7 .. 3-letter combined L2J
|
||||
* 8 .. Model string
|
||||
* </BLOCKQUOTE>
|
||||
*/
|
||||
//! @{
|
||||
virtual void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||
virtual void sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) = 0;
|
||||
//! @}
|
||||
|
||||
//! @}
|
||||
////////////////////////////////////////////////////////////////
|
||||
//! \name ATC slots
|
||||
@@ -471,10 +500,23 @@ namespace BlackCore
|
||||
void textMessagesReceived(const BlackMisc::Network::CTextMessageList &messages);
|
||||
|
||||
/*!
|
||||
* We received a custom packet. It is the slot's responsibility to decode the data.
|
||||
* We received a custom packet.
|
||||
* \deprecated As a short cut you can use this signal directly, but it is better to implement the decoding in INetwork and add a new signal.
|
||||
*/
|
||||
void customPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data);
|
||||
|
||||
/*!
|
||||
* We received an FSInn custom packet.
|
||||
*/
|
||||
void fsipiCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||
|
||||
/*!
|
||||
* We received an FSInn custom response packet.
|
||||
*/
|
||||
void fsipirCustomPacketReceived(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString);
|
||||
|
||||
//! @}
|
||||
////////////////////////////////////////////////////////////////
|
||||
//! \name Weather signals
|
||||
|
||||
@@ -33,6 +33,7 @@ namespace BlackCore
|
||||
m_fsdTextCodec(QTextCodec::codecForName("latin1"))
|
||||
{
|
||||
connect(this, &CNetworkVatlib::terminate, this, &INetwork::terminateConnection, Qt::QueuedConnection);
|
||||
connect(this, &INetwork::customPacketReceived, this, &CNetworkVatlib::customPacketDispatcher);
|
||||
|
||||
Q_ASSERT_X(m_fsdTextCodec, "CNetworkVatlib", "Missing default wire text encoding");
|
||||
//TODO reinit m_fsdTextCodec from WireTextEncoding config setting if present
|
||||
@@ -779,14 +780,18 @@ namespace BlackCore
|
||||
catch (...) { exceptionDispatcher(Q_FUNC_INFO); }
|
||||
}
|
||||
|
||||
QStringList CNetworkVatlib::createFsipiCustomPacketData(const QString &unknown01, const QString &airlineIcao, const QString &aircraftIcao, const QString &magicNumber1, const QString &magicNumber2, const QString &magicNumber3, const QString &magicNumber4, const QString &combinedType, const QString &modelString)
|
||||
void CNetworkVatlib::sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign,
|
||||
const QString &airlineIcao, const QString &aircraftIcao, const QString &combinedType, const QString &modelString)
|
||||
{
|
||||
QStringList data { { "0" }, airlineIcao, aircraftIcao, { "" }, { "" }, { "" }, { "" }, combinedType, modelString };
|
||||
sendCustomPacket(callsign, "FSIPI", data);
|
||||
}
|
||||
|
||||
QStringList data;
|
||||
data << unknown01 << airlineIcao << aircraftIcao
|
||||
<< magicNumber1 << magicNumber2 << magicNumber3 << magicNumber4
|
||||
<< combinedType << modelString;
|
||||
return data;
|
||||
void CNetworkVatlib::sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign,
|
||||
const QString &airlineIcao, const QString &aircraftIcao, const QString &combinedType, const QString &modelString)
|
||||
{
|
||||
QStringList data { { "0" }, airlineIcao, aircraftIcao, { "" }, { "" }, { "" }, { "" }, combinedType, modelString };
|
||||
sendCustomPacket(callsign, "FSIPIR", data);
|
||||
}
|
||||
|
||||
/********************************** * * * * * * * * * * * * * * * * * * * ************************************/
|
||||
@@ -913,6 +918,32 @@ namespace BlackCore
|
||||
emit cbvar_cast(cbvar)->customPacketReceived(cbvar_cast(cbvar)->fromFSD(callsign), cbvar_cast(cbvar)->fromFSD(packetId), cbvar_cast(cbvar)->fromFSD(data, dataSize));
|
||||
}
|
||||
|
||||
void CNetworkVatlib::customPacketDispatcher(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data)
|
||||
{
|
||||
if (packetId.compare("FSIPI", Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
if (data.size() < 9)
|
||||
{
|
||||
qDebug() << "Malformed FSIPI packet";
|
||||
}
|
||||
else
|
||||
{
|
||||
emit fsipiCustomPacketReceived(callsign, data[1], data[2], data[7], data[8]);
|
||||
}
|
||||
}
|
||||
else if (packetId.compare("FSIPIR", Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
if (data.size() < 9)
|
||||
{
|
||||
qDebug() << "Malformed FSIPIR packet";
|
||||
}
|
||||
else
|
||||
{
|
||||
emit fsipirCustomPacketReceived(callsign, data[1], data[2], data[7], data[8]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CNetworkVatlib::onMetarReceived(Cvatlib_Network *, const char *data, void *cbvar)
|
||||
{
|
||||
emit cbvar_cast(cbvar)->metarReplyReceived(cbvar_cast(cbvar)->fromFSD(data));
|
||||
|
||||
@@ -52,6 +52,10 @@ namespace BlackCore
|
||||
virtual void sendIpQuery() override;
|
||||
virtual void sendServerQuery(const BlackMisc::Aviation::CCallsign &callsign) override;
|
||||
virtual void sendCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data) override;
|
||||
virtual void sendFsipiCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) override;
|
||||
virtual void sendFsipirCustomPacket(const BlackMisc::Aviation::CCallsign &callsign, const QString &airlineDesignator,
|
||||
const QString &aircraftDesignator, const QString &combinedType, const QString &modelString) override;
|
||||
|
||||
// Text message slots
|
||||
virtual void sendTextMessages(const BlackMisc::Network::CTextMessageList &messages) override;
|
||||
@@ -78,29 +82,6 @@ namespace BlackCore
|
||||
virtual void sendMetarQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override;
|
||||
virtual void sendWeatherDataQuery(const BlackMisc::Aviation::CAirportIcao &airportIcao) override;
|
||||
|
||||
// some helper methods
|
||||
|
||||
/*!
|
||||
* \brief Create the data load for FSIPI(R) packets / FsInn
|
||||
* \details FSIPI(R) queries
|
||||
* <BLOCKQUOTE>
|
||||
* index 0 .. 0/1 ???
|
||||
* 1 .. MQT, GEC, DLH -> Airline ICAO, most of the time empty
|
||||
* 2 .. AIRCRAFT ICAO "B747"
|
||||
* 3 .. 10.64195
|
||||
* 4 .. 1.06080:
|
||||
* 5 .. 5825.00000
|
||||
* 6 .. 4.DD89CCB6.EC9BB7D7
|
||||
* 7 .. 3-letter combined L2J
|
||||
* 8 .. Model string
|
||||
* </BLOCKQUOTE>
|
||||
* \remarks This helper here has more or less the function of documenting the packet,
|
||||
* it is nothing but a little string concatenating
|
||||
*/
|
||||
static QStringList createFsipiCustomPacketData(const QString &unknown01, const QString &airlineDesignator, const QString &aircraftDesignator,
|
||||
const QString &magicNumber1, const QString &magicNumber2, const QString &magicNumber3, const QString &magicNumber4,
|
||||
const QString &combinedType, const QString &modelString);
|
||||
|
||||
private slots:
|
||||
void replyToFrequencyQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
void replyToNameQuery(const BlackMisc::Aviation::CCallsign &callsign);
|
||||
@@ -146,6 +127,7 @@ namespace BlackCore
|
||||
private slots:
|
||||
void process();
|
||||
void update();
|
||||
void customPacketDispatcher(const BlackMisc::Aviation::CCallsign &callsign, const QString &packetId, const QStringList &data);
|
||||
|
||||
signals:
|
||||
void terminate(); //!< \private
|
||||
|
||||
Reference in New Issue
Block a user