summaryrefslogtreecommitdiff
path: root/psk_reporter.cpp
diff options
context:
space:
mode:
authorIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
committerIain R. Learmonth <irl@debian.org>2015-10-18 18:51:00 +0100
commitd63dd8d081a6fcd0715cd13f26df59fb831769d2 (patch)
treeb9c1f6245147a310aac3762630bad389bbb57335 /psk_reporter.cpp
parentc720a3d55c5ec832c29cb7ce50b6fb4b70c55b11 (diff)
Imported Upstream version 1.5.0upstream/1.5.0
Diffstat (limited to 'psk_reporter.cpp')
-rw-r--r--psk_reporter.cpp59
1 files changed, 41 insertions, 18 deletions
diff --git a/psk_reporter.cpp b/psk_reporter.cpp
index 6856d174..dd2b424e 100644
--- a/psk_reporter.cpp
+++ b/psk_reporter.cpp
@@ -5,17 +5,27 @@
#include "psk_reporter.h"
-PSK_Reporter::PSK_Reporter(QObject *parent) :
- QObject(parent),
- m_sequenceNumber(0)
+#include <QHostInfo>
+#include <QTimer>
+
+#include "MessageClient.hpp"
+
+#include "moc_psk_reporter.cpp"
+
+PSK_Reporter::PSK_Reporter(MessageClient * message_client, QObject *parent) :
+ QObject {parent},
+ m_messageClient {message_client},
+ reportTimer {new QTimer {this}},
+ m_sequenceNumber {0}
{
m_header_h = "000Allllttttttttssssssssiiiiiiii";
// We use 50E2 and 50E3 for link Id
- m_rxInfoDescriptor_h = "0003002450E200030000"
- "8002FFFF0000768F" // 2. Rx Call
- "8004FFFF0000768F" // 4. Rx Grid
- "8008FFFF0000768F" // 8. Rx Soft
+ m_rxInfoDescriptor_h = "0003002C50E200040000"
+ "8002FFFF0000768F" // 2. Rx Call
+ "8004FFFF0000768F" // 4. Rx Grid
+ "8008FFFF0000768F" // 8. Rx Soft
+ "8009FFFF0000768F" // 9. Rx Antenna
"0000";
m_txInfoDescriptor_h = "0002003C50E30007"
@@ -31,18 +41,18 @@ PSK_Reporter::PSK_Reporter(QObject *parent) :
qsrand(QDateTime::currentDateTime().toTime_t());
m_randomId_h = QString("%1").arg(qrand(),8,16,QChar('0'));
- m_udpSocket = new QUdpSocket(this);
+ QHostInfo::lookupHost("report.pskreporter.info", this, SLOT(dnsLookupResult(QHostInfo)));
- reportTimer = new QTimer(this);
connect(reportTimer, SIGNAL(timeout()), this, SLOT(sendReport()));
+ reportTimer->start(5*60*1000); // 5 minutes;
}
-void PSK_Reporter::setLocalStation(QString call, QString gridSquare, QString programInfo)
+void PSK_Reporter::setLocalStation(QString call, QString gridSquare, QString antenna, QString programInfo)
{
m_rxCall = call;
m_rxGrid = gridSquare;
+ m_rxAnt = antenna;
m_progId = programInfo;
- reportTimer->start(5*60*1000); // 5 minutes;
}
void PSK_Reporter::addRemoteStation(QString call, QString grid, QString freq, QString mode, QString snr, QString time )
@@ -59,8 +69,11 @@ void PSK_Reporter::addRemoteStation(QString call, QString grid, QString freq, QS
void PSK_Reporter::sendReport()
{
- if (m_spotQueue.isEmpty())
+ if (m_spotQueue.isEmpty()) {
return;
+ }
+
+ QString report_h;
// Header
QString header_h = m_header_h;
@@ -73,10 +86,11 @@ void PSK_Reporter::sendReport()
rxInfoData_h += QString("%1").arg(m_rxCall.length(),2,16,QChar('0')) + m_rxCall.toUtf8().toHex();
rxInfoData_h += QString("%1").arg(m_rxGrid.length(),2,16,QChar('0')) + m_rxGrid.toUtf8().toHex();
rxInfoData_h += QString("%1").arg(m_progId.length(),2,16,QChar('0')) + m_progId.toUtf8().toHex();
+ rxInfoData_h += QString("%1").arg(m_rxAnt.length(),2,16,QChar('0')) + m_rxAnt.toUtf8().toHex();
rxInfoData_h += "0000";
rxInfoData_h.replace("50E2llll", "50E2" + QString("%1").arg(rxInfoData_h.length()/2,4,16,QChar('0')));
- // Sender information
+ // Sender information
QString txInfoData_h = "50E3llll";
while (!m_spotQueue.isEmpty()) {
QHash<QString,QString> spot = m_spotQueue.dequeue();
@@ -90,15 +104,24 @@ void PSK_Reporter::sendReport()
}
txInfoData_h += "0000";
txInfoData_h.replace("50E3llll", "50E3" + QString("%1").arg(txInfoData_h.length()/2,4,16,QChar('0')));
+ report_h = header_h + m_rxInfoDescriptor_h + m_txInfoDescriptor_h + rxInfoData_h + txInfoData_h;
+ //qDebug() << "Sending Report TX: ";
- // Build report
- QString report_h = header_h + m_rxInfoDescriptor_h + m_txInfoDescriptor_h + rxInfoData_h + txInfoData_h;
report_h.replace("000Allll", "000A" + QString("%1").arg(report_h.length()/2,4,16,QChar('0')));
QByteArray report = QByteArray::fromHex(report_h.toUtf8());
- // Get IP address for pskreporter.info and send report via UDP
- QHostInfo info = QHostInfo::fromName("report.pskreporter.info");
- m_udpSocket->writeDatagram(report,info.addresses().at(0),4739);
+ // Send data to PSK Reporter site
+ if (!m_pskReporterAddress.isNull()) {
+ m_messageClient->send_raw_datagram (report, m_pskReporterAddress, 4739);
+ }
+}
+
+void PSK_Reporter::dnsLookupResult(QHostInfo info)
+{
+ if (!info.addresses().isEmpty()) {
+ m_pskReporterAddress = info.addresses().at(0);
+// qDebug() << "PSK Reporter IP: " << m_pskReporterAddress;
+ }
}