mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 20:15:35 +08:00
Detect textmessage being a SELCAL call
This commit is contained in:
committed by
Mathew Sutcliffe
parent
f5ec7ea864
commit
e60acb25c3
@@ -3,6 +3,7 @@
|
||||
#include "blackmisc/pqconstants.h"
|
||||
#include "blackmisc/aviocomsystem.h"
|
||||
#include "blackmisc/avcallsign.h"
|
||||
#include "blackmisc/avselcal.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
|
||||
@@ -179,6 +180,49 @@ namespace BlackMisc
|
||||
qSwap(this->m_senderCallsign, this->m_recipientCallsign);
|
||||
}
|
||||
|
||||
/*
|
||||
* Find out if this is a SELCAL message
|
||||
*/
|
||||
bool CTextMessage::isSelcalMessage() const
|
||||
{
|
||||
// some first level checks, before really parsing the message
|
||||
if (this->isEmpty()) return false;
|
||||
if (this->isPrivateMessage()) return false;
|
||||
if (this->m_message.length() > 15 || this->m_message.length() < 10) return false; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
|
||||
return this->getSelcalCode().length() == 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* Matching given SELCAL code
|
||||
*/
|
||||
bool CTextMessage::isSelcalMessageFor(const QString &selcal) const
|
||||
{
|
||||
if (!CSelcal::isValidCode(selcal)) return false;
|
||||
return selcal.toUpper() == this->getSelcalCode();
|
||||
}
|
||||
|
||||
/*
|
||||
* SELCAL code, 4 letters
|
||||
*/
|
||||
QString CTextMessage::getSelcalCode() const
|
||||
{
|
||||
// http://forums.vatsim.net/viewtopic.php?f=8&t=63467#p458062
|
||||
// When the ATC client sends a selcal, it goes out as a text message
|
||||
// on their primary frequency, formatted like so:
|
||||
// SELCAL AB-CD
|
||||
|
||||
const QString invalid;
|
||||
|
||||
// some first level checks, before really parsing the message
|
||||
if (this->isEmpty()) return invalid;
|
||||
if (this->isPrivateMessage()) return invalid;
|
||||
if (this->m_message.length() > 15 || this->m_message.length() < 10) return invalid; // SELCAL AB-CD -> 12, I allow some more characters as I do not know wheter in real life it exactly matches
|
||||
QString candidate = this->m_message.toUpper().remove(QRegExp("[^A-Z]")); // SELCALABCD
|
||||
if (candidate.length() != 10) return invalid;
|
||||
if (!candidate.startsWith("SELCAL")) return invalid;
|
||||
return candidate.right(4);
|
||||
}
|
||||
|
||||
/*
|
||||
* Equal?
|
||||
*/
|
||||
|
||||
@@ -45,14 +45,6 @@ namespace BlackMisc
|
||||
CTextMessage(const QString &message, const BlackMisc::Aviation::CCallsign &senderCallsign, const BlackMisc::Aviation::CCallsign &recipientCallsign = BlackMisc::Aviation::CCallsign())
|
||||
: m_message(message), m_received(QDateTime::currentDateTimeUtc()), m_senderCallsign(senderCallsign), m_recipientCallsign(recipientCallsign), m_frequency(-1.0, BlackMisc::PhysicalQuantities::CFrequencyUnit::MHz()) {}
|
||||
|
||||
/*!
|
||||
* \brief QVariant, required for DBus QVariant lists
|
||||
*/
|
||||
virtual QVariant toQVariant() const
|
||||
{
|
||||
return QVariant::fromValue(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* Get callsign (from)
|
||||
*/
|
||||
@@ -179,6 +171,22 @@ namespace BlackMisc
|
||||
*/
|
||||
void toggleSenderRecipient();
|
||||
|
||||
/*!
|
||||
* \brief Is this a text message encapsulating a SELCAL
|
||||
* \see http://forums.vatsim.net/viewtopic.php?f=8&t=63467
|
||||
*/
|
||||
bool isSelcalMessage() const;
|
||||
|
||||
/*!
|
||||
* \brief Is this a text message encapsulating a SELCAL for given code
|
||||
*/
|
||||
bool isSelcalMessageFor(const QString &selcal) const;
|
||||
|
||||
/*!
|
||||
* \brief Get SELCAL code (if applicable, e.g. ABCD), otherwise ""
|
||||
*/
|
||||
QString getSelcalCode() const;
|
||||
|
||||
/*!
|
||||
* \brief Equal operator ==
|
||||
*/
|
||||
@@ -194,6 +202,14 @@ namespace BlackMisc
|
||||
*/
|
||||
virtual uint getValueHash() const;
|
||||
|
||||
/*!
|
||||
* \copydoc CValueObject::toQVariant()
|
||||
*/
|
||||
virtual QVariant toQVariant() const
|
||||
{
|
||||
return QVariant::fromValue(*this);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Register metadata
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user