2018-07-11 23:09:22 -04:00
|
|
|
#ifndef VARICODE_H
|
|
|
|
#define VARICODE_H
|
|
|
|
|
2018-07-12 09:54:56 -04:00
|
|
|
/**
|
|
|
|
* (C) 2018 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include <QBitArray>
|
2018-07-12 15:14:41 -04:00
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QRegExp>
|
2018-07-11 23:09:22 -04:00
|
|
|
#include <QString>
|
2018-07-12 09:54:56 -04:00
|
|
|
#include <QVector>
|
2018-10-02 09:44:46 -04:00
|
|
|
#include <QThread>
|
2018-07-11 23:09:22 -04:00
|
|
|
|
|
|
|
class Varicode
|
|
|
|
{
|
|
|
|
public:
|
2018-07-29 22:40:34 -04:00
|
|
|
// frame type transmitted via itype and decoded by the ft8 decoded
|
|
|
|
enum TransmissionType {
|
2018-08-11 18:05:36 -04:00
|
|
|
FT8Call = 0, // [000] <- any other frame of the message
|
|
|
|
FT8CallFirst = 1, // [001] <- the first frame of a message
|
|
|
|
FT8CallLast = 2, // [010] <- the last frame of a message
|
|
|
|
FT8CallReserved = 4, // [100] <- a reserved flag for future use...
|
2018-07-18 16:45:27 -04:00
|
|
|
};
|
|
|
|
|
2018-07-29 22:40:34 -04:00
|
|
|
enum FrameType {
|
2018-08-03 17:07:36 -04:00
|
|
|
FrameUnknown = 255, // [11111111] <- only used as a sentinel
|
|
|
|
FrameBeacon = 0, // [000]
|
|
|
|
FrameCompound = 1, // [001]
|
|
|
|
FrameCompoundDirected = 2, // [010]
|
2018-08-06 10:29:57 -04:00
|
|
|
FrameDirected = 3, // [011]
|
|
|
|
FrameReservedA = 4, // [100] <- Reserved for future use, likely an extension of one of these formats.
|
2018-10-03 12:36:45 -04:00
|
|
|
FrameDataUncompressed = 5, // [101]
|
|
|
|
FrameDataCompressed = 6, // [110]
|
2018-08-06 10:29:57 -04:00
|
|
|
FrameReservedB = 7, // [111] <- Reserved for future use, likely binary data / other formats.
|
2018-07-29 22:40:34 -04:00
|
|
|
};
|
|
|
|
|
2018-08-04 11:19:07 -04:00
|
|
|
static const quint8 FrameTypeMax = 7;
|
|
|
|
|
|
|
|
static QString frameTypeString(quint8 type) {
|
|
|
|
const char* FrameTypeStrings[] = {
|
|
|
|
"FrameBeacon",
|
|
|
|
"FrameCompound",
|
|
|
|
"FrameCompoundDirected",
|
2018-08-14 22:26:49 -04:00
|
|
|
"FrameDirected",
|
|
|
|
"FrameReservedA",
|
2018-10-03 12:36:45 -04:00
|
|
|
"FrameDataUncompressed",
|
|
|
|
"FrameDataCompressed",
|
2018-08-14 22:26:49 -04:00
|
|
|
"FrameReservedB"
|
2018-08-04 11:19:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
if(type > FrameTypeMax){
|
|
|
|
return "FrameUnknown";
|
|
|
|
}
|
|
|
|
return FrameTypeStrings[type];
|
|
|
|
}
|
|
|
|
|
2018-07-11 23:09:22 -04:00
|
|
|
//Varicode();
|
|
|
|
|
2018-10-02 09:44:46 -04:00
|
|
|
static QString rstrip(const QString& str);
|
|
|
|
static QString lstrip(const QString& str);
|
|
|
|
|
2018-09-20 10:04:18 -04:00
|
|
|
static QMap<QString, QString> defaultHuffTable();
|
2018-09-06 15:22:24 -04:00
|
|
|
static QString cqString(int number);
|
2018-09-18 10:53:43 -04:00
|
|
|
static bool startsWithCQ(QString text);
|
2018-07-20 11:40:55 -04:00
|
|
|
static QString formatSNR(int snr);
|
2018-07-21 02:18:15 -04:00
|
|
|
static QString formatPWR(int dbm);
|
2018-07-20 11:40:55 -04:00
|
|
|
|
2018-07-24 23:10:47 -04:00
|
|
|
static QString checksum16(QString const &input);
|
|
|
|
static bool checksum16Valid(QString const &checksum, QString const &input);
|
|
|
|
|
|
|
|
static QString checksum32(QString const &input);
|
|
|
|
static bool checksum32Valid(QString const &checksum, QString const &input);
|
2018-07-23 08:51:29 -04:00
|
|
|
|
2018-07-12 15:14:41 -04:00
|
|
|
static QStringList parseCallsigns(QString const &input);
|
|
|
|
static QStringList parseGrids(QString const &input);
|
|
|
|
|
2018-07-30 21:26:36 -04:00
|
|
|
static QList<QPair<int, QVector<bool>>> huffEncode(const QMap<QString, QString> &huff, QString const& text);
|
|
|
|
static QString huffDecode(const QMap<QString, QString> &huff, QVector<bool> const& bitvec);
|
2018-10-03 12:36:45 -04:00
|
|
|
static QSet<QString> huffValidChars(const QMap<QString, QString> &huff);
|
2018-07-12 15:14:41 -04:00
|
|
|
|
2018-07-15 15:43:29 -04:00
|
|
|
static QVector<bool> bytesToBits(char * bitvec, int n);
|
2018-07-12 18:02:54 -04:00
|
|
|
static QVector<bool> strToBits(QString const& bitvec);
|
|
|
|
static QString bitsToStr(QVector<bool> const& bitvec);
|
2018-07-12 09:54:56 -04:00
|
|
|
|
2018-07-12 18:02:54 -04:00
|
|
|
static QVector<bool> intToBits(quint64 value, int expected=0);
|
|
|
|
static quint64 bitsToInt(QVector<bool> const value);
|
2018-07-15 15:43:29 -04:00
|
|
|
static quint64 bitsToInt(QVector<bool>::ConstIterator start, int n);
|
2018-07-26 12:47:03 -04:00
|
|
|
static QVector<bool> bitsListToBits(QList<QVector<bool>> &list);
|
2018-07-12 09:54:56 -04:00
|
|
|
|
2018-07-12 18:02:54 -04:00
|
|
|
static quint8 unpack5bits(QString const& value);
|
|
|
|
static QString pack5bits(quint8 packed);
|
2018-07-12 09:54:56 -04:00
|
|
|
|
2018-07-23 15:28:36 -04:00
|
|
|
static quint8 unpack6bits(QString const& value);
|
|
|
|
static QString pack6bits(quint8 packed);
|
|
|
|
|
2018-07-12 18:02:54 -04:00
|
|
|
static quint16 unpack16bits(QString const& value);
|
|
|
|
static QString pack16bits(quint16 packed);
|
2018-07-12 09:54:56 -04:00
|
|
|
|
2018-07-12 18:02:54 -04:00
|
|
|
static quint32 unpack32bits(QString const& value);
|
|
|
|
static QString pack32bits(quint32 packed);
|
|
|
|
|
|
|
|
static quint64 unpack64bits(QString const& value);
|
|
|
|
static QString pack64bits(quint64 packed);
|
2018-07-13 00:55:48 -04:00
|
|
|
|
2018-08-06 10:16:20 -04:00
|
|
|
static quint64 unpack72bits(QString const& value, quint8 *pRem);
|
2018-08-06 09:37:43 -04:00
|
|
|
static QString pack72bits(quint64 value, quint8 rem);
|
|
|
|
|
2018-08-01 11:25:45 -04:00
|
|
|
static quint32 packAlphaNumeric22(QString const& value, bool isFlag);
|
|
|
|
static QString unpackAlphaNumeric22(quint32 packed, bool *isFlag);
|
2018-07-23 15:28:36 -04:00
|
|
|
|
2018-07-13 00:55:48 -04:00
|
|
|
static quint32 packCallsign(QString const& value);
|
|
|
|
static QString unpackCallsign(quint32 value);
|
|
|
|
|
2018-08-27 21:19:38 -04:00
|
|
|
static QString deg2grid(float dlong, float dlat);
|
|
|
|
static QPair<float, float> grid2deg(QString const &grid);
|
2018-07-13 21:59:54 -04:00
|
|
|
static quint16 packGrid(QString const& value);
|
|
|
|
static QString unpackGrid(quint16 value);
|
|
|
|
|
2018-08-03 17:07:36 -04:00
|
|
|
static quint8 packNum(QString const &num, bool *ok);
|
|
|
|
static quint8 packPwr(QString const &pwr, bool *ok);
|
2018-08-04 11:19:07 -04:00
|
|
|
static quint8 packCmd(quint8 cmd, quint8 num, bool *pPackedNum);
|
2018-08-03 17:07:36 -04:00
|
|
|
static quint8 unpackCmd(quint8 value, quint8 *pNum);
|
|
|
|
|
2018-09-21 01:47:21 -04:00
|
|
|
static bool isSNRCommand(const QString &cmd);
|
2018-07-19 02:09:19 -04:00
|
|
|
static bool isCommandAllowed(const QString &cmd);
|
2018-07-25 22:49:19 -04:00
|
|
|
static bool isCommandBuffered(const QString &cmd);
|
2018-08-27 22:04:17 -04:00
|
|
|
static int isCommandChecksumed(const QString &cmd);
|
2018-07-24 02:47:14 -04:00
|
|
|
|
2018-07-29 10:39:58 -04:00
|
|
|
static QString packBeaconMessage(QString const &text, QString const&callsign, int *n);
|
2018-09-06 15:22:24 -04:00
|
|
|
static QStringList unpackBeaconMessage(const QString &text, quint8 *pType, bool *isAlt, quint8 *pBits3);
|
2018-07-27 16:11:11 -04:00
|
|
|
|
2018-08-02 01:38:47 -04:00
|
|
|
static QString packCompoundMessage(QString const &text, int *n);
|
2018-09-06 15:22:24 -04:00
|
|
|
static QStringList unpackCompoundMessage(const QString &text, quint8 *pType, quint8 *pBits3);
|
2018-08-02 01:38:47 -04:00
|
|
|
|
2018-09-06 15:22:24 -04:00
|
|
|
static QString packCompoundFrame(const QString &baseCallsign, const QString &fix, bool isPrefix, quint8 type, quint16 num, quint8 bits3);
|
|
|
|
static QStringList unpackCompoundFrame(const QString &text, quint8 *pType, quint16 *pNum, quint8 *pBits3);
|
2018-07-24 02:47:14 -04:00
|
|
|
|
2018-08-03 17:07:36 -04:00
|
|
|
static QString packDirectedMessage(QString const& text, QString const& callsign, QString *pTo, QString * pCmd, QString *pNum, int *n);
|
|
|
|
static QStringList unpackDirectedMessage(QString const& text, quint8 *pType);
|
2018-07-19 03:44:02 -04:00
|
|
|
|
2018-08-03 17:07:36 -04:00
|
|
|
static QString packDataMessage(QString const& text, int *n);
|
|
|
|
static QString unpackDataMessage(QString const& text, quint8 *pType);
|
2018-10-02 09:44:46 -04:00
|
|
|
|
|
|
|
static QStringList buildMessageFrames(
|
|
|
|
QString const& mycall,
|
|
|
|
QString const& basecall,
|
|
|
|
QString const& mygrid,
|
|
|
|
bool compound,
|
|
|
|
QString const& selectedCall,
|
|
|
|
QString const& text
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class BuildMessageFramesThread : public QThread
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
BuildMessageFramesThread(QString const& mycall,
|
|
|
|
QString const& basecall,
|
|
|
|
QString const& mygrid,
|
|
|
|
bool compound,
|
|
|
|
QString const& selectedCall,
|
|
|
|
QString const& text,
|
|
|
|
QObject *parent=nullptr);
|
|
|
|
void run() override;
|
|
|
|
signals:
|
|
|
|
void resultReady(const QStringList s);
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString m_mycall;
|
|
|
|
QString m_basecall;
|
|
|
|
QString m_mygrid;
|
|
|
|
bool m_compound;
|
|
|
|
QString m_selectedCall;
|
|
|
|
QString m_text;
|
2018-07-11 23:09:22 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VARICODE_H
|