File: APRSISClient.h

package info (click to toggle)
js8call 2.5.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,720 kB
  • sloc: cpp: 562,651; sh: 898; python: 132; ansic: 102; makefile: 4
file content (78 lines) | stat: -rw-r--r-- 2,031 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef APRSISCLIENT_H
#define APRSISCLIENT_H

#include <QDateTime>
#include <QLoggingCategory>
#include <QPair>
#include <QQueue>
#include <QTcpSocket>
#include <QTimer>
#include <QtGlobal>

Q_DECLARE_LOGGING_CATEGORY(aprsisclient_js8)

class APRSISClient : public QTcpSocket {
  public:
    APRSISClient(QString host, quint16 port, QObject *parent = nullptr);

    static quint32 hashCallsign(QString callsign);
    static QString loginFrame(QString callsign);
    static QPair<float, float> grid2deg(QString grid);
    static QPair<QString, QString> grid2aprs(QString grid);
    static QString stripSSID(QString call);
    static QString replaceCallsignSuffixWithSSID(QString call, QString base);

    bool isPasscodeValid() {
        return m_localPasscode == QString::number(hashCallsign(m_localCall));
    }

    void enqueueRaw(QString aprsFrame);
    void processQueue(bool disconnect = true);

  public slots:

    void setSkipPercent(float skipPercent) { m_skipPercent = skipPercent; }

    void setServer(QString host, quint16 port) {
        if (state() == QTcpSocket::ConnectedState) {
            disconnectFromHost();
        }

        m_host = host;
        m_port = port;

        qCDebug(aprsisclient_js8)
            << "APRSISClient Server Change:" << m_host << m_port;
    }

    void setPaused(bool paused) { m_paused = paused; }

    void setLocalStation(QString mycall, QString passcode) {
        m_localCall = mycall;
        m_localPasscode = passcode;
    }

    void enqueueSpot(QString by_call, QString from_call, QString grid,
                     QString comment);
    void enqueueThirdParty(QString by_call, QString from_call, QString text);

    void sendReports() {
        if (m_paused)
            return;

        processQueue(true);
    }

  private:
    QString m_localCall;
    QString m_localPasscode;

    QQueue<QPair<QString, QDateTime>> m_frameQueue;
    QString m_host;
    quint16 m_port;
    QTimer m_timer;
    bool m_paused;
    float m_skipPercent;
};

#endif // APRSISCLIENT_H