Skip to content

Commit

Permalink
Frequency tests update
Browse files Browse the repository at this point in the history
  • Loading branch information
d authored and d committed May 1, 2024
1 parent 8516b74 commit 9ee9793
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 59 deletions.
53 changes: 22 additions & 31 deletions src/dxcluster/dxcluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,43 +332,35 @@ void DXClusterWidget::setCurrentLog(const int _log)

void DXClusterWidget::slotClusterDataArrived()
{
qDebug() << Q_FUNC_INFO;
//qDebug() << Q_FUNC_INFO;
//QStringList qs;
QString dxClusterString;
QString dxCall;
QString spotBand;
Frequency freq;
QString spotBand = "-1";


spotBand = "-1";

QString spotter;
//QString spotter;
EntityStatus _entityStatus;
while ( tcpSocket->canReadLine() )
{
spotter.clear();
dxCall.clear();
_entityStatus.entityId = -1;

dxClusterString = tcpSocket->readLine();
dxClusterString = dxClusterString.trimmed();
// Remove BELL-string if exists
dxClusterString = dxClusterString.remove("\a");
qDebug() << Q_FUNC_INFO << ": Line: " << dxClusterString;

//qDebug() << Q_FUNC_INFO << ": Line: " << dxClusterString;
saveSpot(dxClusterString);
DXSpot spot = readItem(dxClusterString);

if (spot.valid)
{
qDebug() << Q_FUNC_INFO << " - Spot IS valid";
_entityStatus.entityId = world->getQRZARRLId(dxCall);
spotBand = QString::number(dataProxy->getBandIdFromFreq(freq.toDouble()) );
_entityStatus.entityId = world->getQRZARRLId(spot.dxcall);
spotBand = QString::number(dataProxy->getBandIdFromFreq(spot.freq.toDouble()) );

dxSpotColor = awards->getQRZDXStatusColor(_entityStatus);
if (showDxMarathon)
{
if (awards->isDXMarathonNeed(_entityStatus.entityId, world->getQRZCqz(dxCall), QDateTime::currentDateTime().date().year(), currentLog))
if (awards->isDXMarathonNeed(_entityStatus.entityId, world->getQRZCqz(spot.dxcall), QDateTime::currentDateTime().date().year(), currentLog))
{
dxClusterString = dxClusterString + " ### Needed for DXMarathon - " + QString::number(QDateTime::currentDateTime().date().year()) + " ###";
}
Expand All @@ -386,7 +378,7 @@ void DXClusterWidget::slotClusterDataArrived()
_entityStatus.modeId = -1;
if (!checkIfNeedsToBePrinted(_entityStatus))
{
qDebug() << Q_FUNC_INFO << " - Not to be printed!: " << dxCall;
qDebug() << Q_FUNC_INFO << " - Not to be printed!: " << spot.dxcall;
return;
}

Expand All @@ -399,12 +391,11 @@ void DXClusterWidget::slotClusterDataArrived()
if (!spot.valid)
return;

qDebug() << Q_FUNC_INFO << " - DXCall: " << spot.dxcall;
qDebug() << Q_FUNC_INFO << " - Freq-string: " << freq.toQString();
qDebug() << Q_FUNC_INFO << " - Freq-double: " << QString::number(freq.toDouble());
qDebug() << Q_FUNC_INFO << " - DXCall: " << spot.dxcall;
qDebug() << Q_FUNC_INFO << " - Freq-string: " << spot.freq.toQString();
qDebug() << Q_FUNC_INFO << " - Freq-double: " << QString::number(spot.freq.toDouble());
qDebug() << Q_FUNC_INFO << " - Everything OK emitting...";

emit dxspotArrived(spot.dxcall, freq.toDouble());
emit dxspotArrived(spot.dxcall, spot.freq.toDouble());
}

qDebug() << Q_FUNC_INFO << " - END";
Expand Down Expand Up @@ -594,7 +585,7 @@ bool DXClusterWidget::isConnected()

DXSpot DXClusterWidget::readItem(const QString _stringSpot)
{
qDebug() << Q_FUNC_INFO;
//qDebug() << Q_FUNC_INFO;

DXSpot spot = DXSpot();
spot.valid = false;
Expand All @@ -612,34 +603,34 @@ DXSpot DXClusterWidget::readItem(const QString _stringSpot)

if ( (fields.at(0) == "DX" ) && (fields.at(1) == "de" ) )
{ // DX de EA0XXX: 21200.1 EA0K The comment 1550
qDebug() << Q_FUNC_INFO << ": Identified: DX de";
qDebug() << Q_FUNC_INFO << ": 0: " << fields.at(0);
qDebug() << Q_FUNC_INFO << ": 1: " << fields.at(1);
qDebug() << Q_FUNC_INFO << ": 2: " << fields.at(2);
//qDebug() << Q_FUNC_INFO << ": Identified: DX de";
//qDebug() << Q_FUNC_INFO << ": 0: " << fields.at(0);
//qDebug() << Q_FUNC_INFO << ": 1: " << fields.at(1);
//qDebug() << Q_FUNC_INFO << ": 2: " << fields.at(2);
qDebug() << Q_FUNC_INFO << ": 3: " << fields.at(3);
qDebug() << Q_FUNC_INFO << ": 4: " << fields.at(4);
qDebug() << Q_FUNC_INFO << ": 5: " << fields.at(5);
//qDebug() << Q_FUNC_INFO << ": 4: " << fields.at(4);
//qDebug() << Q_FUNC_INFO << ": 5: " << fields.at(5);
spot.spotter = fields.at(2);
spot.freq.fromQString((fields.at(3)), KHz);
spot.dxcall = fields.at(4);
spot.valid = true;
}
else if (fields.last().endsWith(">"))
{ // 14250.0 EA0XXX 12-Apr-2020 2140Z Comment <EA0XX>
qDebug() << Q_FUNC_INFO << ": Identified: ENDS with >";
//qDebug() << Q_FUNC_INFO << ": Identified: ENDS with >";
spot.spotter = fields.last();
spot.freq.fromQString((fields.at(0)), KHz);
spot.dxcall = fields.at(1);
spot.valid = true;
}
else if ((fields.at(0) == "To" ) && (fields.at(1) == "ALL" ))
{ // To ALL Comment
qDebug() << Q_FUNC_INFO << ": Identified: To ALL";
//qDebug() << Q_FUNC_INFO << ": Identified: To ALL";
spot.valid = false;
}
else
{
qDebug() << Q_FUNC_INFO << ": Identified: Default";
//qDebug() << Q_FUNC_INFO << ": Identified: Default";
spot.valid = false;
}

Expand Down
22 changes: 15 additions & 7 deletions src/frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,20 @@ double Frequency::toDouble(FreqUnits _u)
return deNormalize(freq, _u);
}

QString Frequency::toQString(int _decimals, FreqUnits _u)
QString Frequency::toQString(FreqUnits _u)
{
//qDebug() << Q_FUNC_INFO << ": " << QString::number(freq);
//qDebug() << Q_FUNC_INFO << ":u: " << QString::number(_u);

double d = toDouble(_u);
//qDebug() << Q_FUNC_INFO << ":d: " << QString::number(freq);

int dec = getDecimals(_u);
//qDebug() << Q_FUNC_INFO << ": " << QString::number(toDouble());
//qDebug() << Q_FUNC_INFO << ": " << QString::number(fmod(toDouble(), 1.0));
//qDebug() << Q_FUNC_INFO << ":u: " << QString::number(_u);


//qDebug() << Q_FUNC_INFO << ": Freq: " << QString::number(toDouble());
//qDebug() << Q_FUNC_INFO << ": dec: " << QString::number(dec);

return QString("%1").arg(d, 0, 'f', dec);
}
Expand Down Expand Up @@ -145,16 +153,16 @@ int Frequency::getDecimals(const FreqUnits _u)
return 0;
break;
case KHz:
return 3;
return 0;
break;
case MHz:
return 6;
return 3;
break;
case GHz:
return 9;
return 6;
break;
case THz:
return 12;
return 9;
break;
default: // Default is in MHz
return 6;
Expand Down
2 changes: 1 addition & 1 deletion src/frequency.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Frequency: public QObject
bool fromQString(const QString &_f, FreqUnits _u = MHz);
//bool fromBand(const QString &_bandName);
double toDouble(FreqUnits _u = MHz); // Returns in MHz
QString toQString(int _decimals = 3, FreqUnits _u = MHz); // Returns in MHz with decimals
QString toQString(FreqUnits _u = MHz); // Returns in MHz with decimals
void setTolerance(const double _t, FreqUnits _u = Hz); // Defines the tolerance
//QString band(); // Returns the band
//int bandId(); // Returns the bandId
Expand Down
22 changes: 11 additions & 11 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,27 +310,27 @@ int main(int argc, char *argv[])
splash.showMessage ("Creating window...");
//qDebug() << Q_FUNC_INFO << " - 102 " << (QTime::currentTime()).toString("HH:mm:ss");
MainWindow mw(version);
qDebug() << Q_FUNC_INFO << " - 103 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 103 " << (QTime::currentTime()).toString("HH:mm:ss");
splash.showMessage ("Initializing window...");
qDebug() << Q_FUNC_INFO << " - 104 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 104 " << (QTime::currentTime()).toString("HH:mm:ss");
mw.init();
qDebug() << Q_FUNC_INFO << " - 105 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 105 " << (QTime::currentTime()).toString("HH:mm:ss");
splash.showMessage ("Checking for new versions...");
qDebug() << Q_FUNC_INFO << " - 106 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 106 " << (QTime::currentTime()).toString("HH:mm:ss");
mw.checkIfNewVersion();
qDebug() << Q_FUNC_INFO << " - 107 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 107 " << (QTime::currentTime()).toString("HH:mm:ss");
splash.showMessage ("Checking if backup is needed...");
qDebug() << Q_FUNC_INFO << " - 108 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 108 " << (QTime::currentTime()).toString("HH:mm:ss");
mw.recommendBackupIfNeeded();
qDebug() << Q_FUNC_INFO << " - 109 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 109 " << (QTime::currentTime()).toString("HH:mm:ss");
splash.showMessage ("Showing window...");
qDebug() << Q_FUNC_INFO << " - 110 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 110 " << (QTime::currentTime()).toString("HH:mm:ss");
mw.show();
qDebug() << Q_FUNC_INFO << " - 111 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 111 " << (QTime::currentTime()).toString("HH:mm:ss");
splash.finish(&mw);
qDebug() << Q_FUNC_INFO << " - 112 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 112 " << (QTime::currentTime()).toString("HH:mm:ss");
mw.showNotWar();
qDebug() << Q_FUNC_INFO << " - 113 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - 113 " << (QTime::currentTime()).toString("HH:mm:ss");
//qDebug() << Q_FUNC_INFO << " - END";
return app.exec();
}
Expand Down
46 changes: 37 additions & 9 deletions tests/tst_frequency/tst_frequency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private slots:
void test_Basic();
void test_toDouble();
void test_toQString();
void test_fromQString();


private:
Expand All @@ -60,11 +61,16 @@ tst_Frequency::tst_Frequency()
freq2 = new Frequency();
}

tst_Frequency::~tst_Frequency(){}
tst_Frequency::~tst_Frequency()
{
delete(freq);
delete(freq2);
}

void tst_Frequency::initTestCase()
{
//qDebug("Called before everything else.");
freq->clear();
freq2->clear();
}

void tst_Frequency::cleanupTestCase()
Expand All @@ -85,20 +91,20 @@ void tst_Frequency::test_Constructors()
void tst_Frequency::test_Basic()
{ //num FreqUnits {Hz, KHz, MHz, GHz, THz};
freq->clear();
QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)0.0), "Freq cleared");
QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)0.0), "Freq failed to be cleared");

freq->fromDouble(28.495);
freq2->clear();
freq2 = freq;
QVERIFY2(qFuzzyCompare(freq->toDouble(),freq2->toDouble()), "Freq assignment (=) not working");
QVERIFY2(freq2->isValid(), "Freq isValid not working");



}

void tst_Frequency::test_toDouble()
{
freq->clear();
QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)0.0), "Freq failed to be cleared");

QVERIFY2(freq->fromDouble(14.195, MHz) == true, "Could not import the double from MHz");
QVERIFY2(qFuzzyCompare(freq->toDouble(THz), (double)0.000014195), "Freq 14.195 in THz");
QVERIFY2(qFuzzyCompare(freq->toDouble(GHz), (double)0.014195), "Freq 14.195 in GHz");
Expand All @@ -118,13 +124,35 @@ void tst_Frequency::test_toDouble()
void tst_Frequency::test_toQString()
{
Frequency freq1(21.295);
qDebug() << Q_FUNC_INFO << ": " << freq1.toQString();
//*freq = freq1;
//qDebug() << Q_FUNC_INFO << ": Hz: " << freq1.toQString(Hz);
QVERIFY2(freq1.toQString(Hz) == QString("21295000"), "toQString(Hz) failed");
QVERIFY2(freq1.toQString(KHz) == QString("21295"), "toQString(KHz) failed");
QVERIFY2(freq1.toQString() == QString("21.295"), "toQString() failed");
QVERIFY2(freq1.toQString(MHz) == QString("21.295"), "toQString(MHz) failed");
QVERIFY2(freq1.toQString(GHz) == QString("0.021295"), "toQString(GHz) failed");
QVERIFY2(freq1.toQString(THz) == QString("0.000021295"), "toQString(THz) failed");
}

void tst_Frequency::test_fromQString()
{
freq->clear();
QVERIFY2(qFuzzyCompare(freq->toDouble(Hz),(double)0.0), "Freq failed to be cleared");

freq->fromQString("14195000", Hz);
QVERIFY2(qFuzzyCompare(freq->toDouble(),(double)14.195), "Freq 14.195 in MHz");

freq->fromQString("14195.000", KHz);
QVERIFY2(qFuzzyCompare(freq->toDouble(),(double)14.195), "Freq 14.195 in MHz");

freq->fromQString("14.195", MHz);
QVERIFY2(qFuzzyCompare(freq->toDouble(),(double)14.195), "Freq 14.195 in MHz");

freq->fromQString("1.296", GHz);
QVERIFY2(qFuzzyCompare(freq->toDouble(),(double)1296.0), "Freq 1296 in MHz");
}
/*
bool fromQString(const QString &_f, FreqUnits _u = MHz);
QString toQString(int _decimals = 3, FreqUnits _u = MHz); // Returns in MHz with decimals
void setTolerance(const double _t, FreqUnits _u = Hz); // Defines the tolerance
*/

Expand Down

0 comments on commit 9ee9793

Please sign in to comment.