Added class for PSK Reporter. Still need to wire class to mainwindow.cpp

git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3182 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
This commit is contained in:
Edson W. R. Pereira 2013-04-16 19:22:53 +00:00
parent d50ca6a077
commit 588d329454
3 changed files with 135 additions and 5 deletions

View File

@ -1,6 +1,114 @@
// KISS Interface for posting spots to PSK Reporter web site
// Implemented by Edson Pereira PY2SDR
//
// Reports will be sent in batch mode every 5 minutes.
// If there are no spots to be sent, a report will be sent with only the receiver station info.
#include "psk_reporter.h" #include "psk_reporter.h"
PSK_Reporter::PSK_Reporter(QObject *parent) : PSK_Reporter::PSK_Reporter(QObject *parent) :
QObject(parent) QObject(parent),
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
"0000";
m_txInfoDescriptor_h = "0002003C50E30007"
"8001FFFF0000768F" // 1. Tx Call
"800500040000768F" // 5. Tx Freq
"800600010000768F" // 6. Tx snr
"800AFFFF0000768F" // 10. Tx Mode
"8003FFFF0000768F" // 3. Tx Grid
"800B00010000768F" // 11. Tx info src
"00960004"; // Tx time
qsrand(QDateTime::currentDateTime().toTime_t());
m_randomId_h = QString("%1").arg(qrand(),8,16,QChar('0'));
m_udpSocket = new QUdpSocket(this);
m_udpSocket->bind(QHostAddress::LocalHost,14739); // Force udp source port
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)
{
m_rxCall = call;
m_rxGrid = gridSquare;
m_progId = programInfo;
}
void PSK_Reporter::addRemoteStation(QString call, QString grid, QString freq, QString mode, QString snr, QString time )
{
QHash<QString,QString> spot;
spot["call"] = call;
spot["grid"] = grid;
spot["snr"] = snr;
spot["freq"] = freq;
spot["mode"] = mode;
spot["time"] = time;
m_spotQueue.enqueue(spot);
}
void PSK_Reporter::sendReport()
{
// Header
QString header_h = m_header_h;
header_h.replace("tttttttt", QString("%1").arg(QDateTime::currentDateTime().toTime_t(),8,16,QChar('0')));
header_h.replace("ssssssss", QString("%1").arg(++m_sequenceNumber,8,16,QChar('0')));
header_h.replace("iiiiiiii", m_randomId_h);
// Receiver information
QString rxInfoData_h = "50E2llll";
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 += "0000";
rxInfoData_h.replace("50E2llll", "50E2" + QString("%1").arg(rxInfoData_h.length()/2,4,16,QChar('0')));
// Sender information
QString txInfoData_h;
if (!m_spotQueue.isEmpty()) {
txInfoData_h = "50E3llll";
while (!m_spotQueue.isEmpty()) {
QHash<QString,QString> spot = m_spotQueue.dequeue();
qDebug() << spot;
txInfoData_h += QString("%1").arg(spot["call"].length(),2,16,QChar('0')) + spot["call"].toUtf8().toHex();
txInfoData_h += QString("%1").arg(spot["freq"].toLongLong(),8,16,QChar('0'));
txInfoData_h += QString("%1").arg(spot["snr"].toInt(),1,16,QChar('0')).mid(14,2);
txInfoData_h += QString("%1").arg(spot["mode"].length(),2,16,QChar('0')) + spot["mode"].toUtf8().toHex();
txInfoData_h += QString("%1").arg(spot["grid"].length(),2,16,QChar('0')) + spot["grid"].toUtf8().toHex();
txInfoData_h += QString("%1").arg(1,2,16,QChar('0'));;
txInfoData_h += QString("%1").arg(spot["time"].toInt(),8,16,QChar('0'));
}
txInfoData_h += "0000";
txInfoData_h.replace("50E3llll", "50E3" + QString("%1").arg(txInfoData_h.length()/2,4,16,QChar('0')));
}
// 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("pskreporter.info");
m_udpSocket->writeDatagram(report,info.addresses().at(0),14739);
qDebug() << header_h;
qDebug() << m_rxInfoDescriptor_h;
qDebug() << m_txInfoDescriptor_h;
qDebug() << rxInfoData_h;
qDebug() << txInfoData_h;
qDebug() << report.toHex();
}

View File

@ -1,18 +1,41 @@
#ifndef PSK_REPORTER_H #ifndef PSK_REPORTER_H
#define PSK_REPORTER_H #define PSK_REPORTER_H
#include <QObject> #include <QtCore>
#include <QUdpSocket>
#include <QHostInfo>
class PSK_Reporter : public QObject class PSK_Reporter : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit PSK_Reporter(QObject *parent = 0); explicit PSK_Reporter(QObject *parent = 0);
void setLocalStation(QString call, QString grid, QString programInfo);
void addRemoteStation(QString call, QString grid, QString freq, QString mode, QString snr, QString time);
signals: signals:
public slots: public slots:
void sendReport();
private:
QString m_header_h;
QString m_rxInfoDescriptor_h;
QString m_txInfoDescriptor_h;
QString m_randomId_h;
QString m_linkId_h;
QString m_rxCall;
QString m_rxGrid;
QString m_progId;
QQueue< QHash<QString,QString> > m_spotQueue;
QUdpSocket *m_udpSocket;
QTimer *reportTimer;
int m_sequenceNumber;
}; };
#endif // PSK_REPORTER_H #endif // PSK_REPORTER_H

View File

@ -59,8 +59,7 @@ RC_FILE = wsjtx.rc
unix { unix {
INCLUDEPATH += $$quote(/usr/include/qwt-qt4) INCLUDEPATH += $$quote(/usr/include/qwt-qt4)
LIBS += ../wsjtx/lib/libjt9.a LIBS += ../wsjtx/lib/libjt9.a
LIBS += /usr/lib/libqwt.so LIBS += -lportaudio -lgfortran -lfftw3f -lqwt-qt4
LIBS += -lportaudio -lgfortran -lfftw3f
} }
win32 { win32 {