diff options
Diffstat (limited to 'psk_reporter.cpp')
| -rw-r--r-- | psk_reporter.cpp | 59 |
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; + } } |
