From c0833aa753ef9c9e9f31c115d7a6c34ad2ab623b Mon Sep 17 00:00:00 2001 From: Jordan Sherer Date: Mon, 23 Jul 2018 08:51:29 -0400 Subject: [PATCH] Added checksum generation and ACK --- varicode.cpp | 22 ++++++++++++++++++++-- varicode.h | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/varicode.cpp b/varicode.cpp index 595801b..34fd19e 100644 --- a/varicode.cpp +++ b/varicode.cpp @@ -44,8 +44,10 @@ QMap directed_cmds = { {"&", 2 }, // query station message {"$", 3 }, // query station(s) heard {"|", 4 }, // relay message + {"!", 5 }, // alert message // directed responses + {" ACK", 23 }, // acknowledge {" PWR", 24 }, // power level {" SNR", 25 }, // seen a station at the provided snr {" NO", 26 }, // negative confirm @@ -56,11 +58,11 @@ QMap directed_cmds = { {" ", 31 }, // send freetext }; -QSet allowed_cmds = {0, 1, 2, 24, 25, 26, 27, 28, 29, 30, 31}; +QSet allowed_cmds = {0, 1, 2, /*3,*/ 4, /*5,*/ 23, 24, 25, 26, 27, 28, 29, 30, 31}; QRegularExpression directed_re("^" "(?[A-Z0-9/]+)" - "(?\\s?(?:AGN[?]|RR|73|YES|NO|SNR|PWR|[?$@&| ]))" + "(?\\s?(?:AGN[?]|RR|73|YES|NO|SNR|PWR|ACK|[?$@&|! ]))" "(?\\s?\\d+\\s?[KM]?W)?" "(?\\s?[-+]?(?:3[01]|[0-2]?[0-9]))?" ); @@ -191,6 +193,22 @@ QString Varicode::formatPWR(int dbm){ return QString("%1W").arg(mwatts/1000); } +QString Varicode::checksum(QString const &input){ + auto fromBytes = input.toLocal8Bit(); + auto crc = CRC::Calculate(fromBytes.data(), fromBytes.length(), CRC::CRC_16_KERMIT()); + auto checksum = Varicode::pack16bits(crc); + if(checksum.length() < 3){ + checksum += QString(" ").repeated(3-checksum.length()); + } + return checksum; +} + +bool Varicode::checksumValid(QString const &checksum, QString const &input){ + auto fromBytes = input.toLocal8Bit(); + auto crc = CRC::Calculate(fromBytes.data(), fromBytes.length(), CRC::CRC_16_KERMIT()); + return Varicode::pack16bits(crc) == checksum; +} + QStringList Varicode::parseCallsigns(QString const &input){ QStringList callsigns; QRegularExpression re(callsign_pattern2); diff --git a/varicode.h b/varicode.h index 90ae8fb..faf9828 100644 --- a/varicode.h +++ b/varicode.h @@ -30,6 +30,9 @@ public: static QString formatSNR(int snr); static QString formatPWR(int dbm); + static QString checksum(QString const &input); + static bool checksumValid(QString const &checksum, QString const &input); + static QStringList parseCallsigns(QString const &input); static QStringList parseGrids(QString const &input);