You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
246 lines
8.4 KiB
246 lines
8.4 KiB
/////////////////////////////////////////////////////////////////////////////////// |
|
// Copyright (C) 2024 Edouard Griffiths, F4EXB <f4exb06@gmail.com> // |
|
// // |
|
// This program is free software; you can redistribute it and/or modify // |
|
// it under the terms of the GNU General Public License as published by // |
|
// the Free Software Foundation as version 3 of the License, or // |
|
// (at your option) any later version. // |
|
// // |
|
// This program is distributed in the hope that it will be useful, // |
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
// GNU General Public License V3 for more details. // |
|
// // |
|
// You should have received a copy of the GNU General Public License // |
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. // |
|
/////////////////////////////////////////////////////////////////////////////////// |
|
|
|
#include "meshtasticmodencoderft.h" |
|
|
|
#ifndef HAS_FT8 |
|
void MeshtasticModEncoderFT::encodeMsg( |
|
const QString& myCall, |
|
const QString& urCall, |
|
const QString& myLocator, |
|
const QString& myReport, |
|
const QString& textMessage, |
|
MeshtasticModSettings::MessageType messageType, |
|
unsigned int nbSymbolBits, |
|
std::vector<unsigned short>& symbols |
|
) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsg: not implemented"); |
|
} |
|
#else |
|
|
|
#include "ft8.h" |
|
#include "packing.h" |
|
|
|
|
|
void MeshtasticModEncoderFT::encodeMsg( |
|
const QString& myCall, |
|
const QString& urCall, |
|
const QString& myLocator, |
|
const QString& myReport, |
|
const QString& textMessage, |
|
MeshtasticModSettings::MessageType messageType, |
|
unsigned int nbSymbolBits, |
|
std::vector<unsigned short>& symbols |
|
) |
|
{ |
|
int a174[174]; // FT payload is 174 bits |
|
|
|
if (messageType == MeshtasticModSettings::MessageNone) { |
|
return; // do nothing |
|
} else if (messageType == MeshtasticModSettings::MessageBeacon) { |
|
encodeMsgBeaconOrCQ(myCall, myLocator, "DE", a174); |
|
} else if (messageType == MeshtasticModSettings::MessageCQ) { |
|
encodeMsgBeaconOrCQ(myCall, myLocator, "CQ", a174); |
|
} else if (messageType == MeshtasticModSettings::MessageReply) { |
|
encodeMsgReply(myCall, urCall, myLocator, a174); |
|
} else if (messageType == MeshtasticModSettings::MessageReport) { |
|
encodeMsgReport(myCall, urCall, myReport, 0, a174); |
|
} else if (messageType == MeshtasticModSettings::MessageReplyReport) { |
|
encodeMsgReport(myCall, urCall, myReport, 1, a174); |
|
} else if (messageType == MeshtasticModSettings::MessageRRR) { |
|
encodeMsgReport(myCall, urCall, "RRR", 1, a174); |
|
} else if (messageType == MeshtasticModSettings::Message73) { |
|
encodeMsgReport(myCall, urCall, "73", 1, a174); |
|
} else { |
|
encodeTextMsg(textMessage, a174); |
|
} |
|
|
|
int allBits = ((174 / nbSymbolBits) + (174 % nbSymbolBits == 0 ? 0 : 1))*nbSymbolBits; // ensures zero bits padding |
|
int iBit; |
|
int symbol = 0; |
|
|
|
interleave174(a174); |
|
|
|
for (int i = 0; i < allBits; i++) |
|
{ |
|
iBit = nbSymbolBits - (i % nbSymbolBits) - 1; // MSB first |
|
|
|
if (i < 174) { |
|
symbol += a174[i] * (1<<iBit); |
|
} |
|
|
|
if ((i % nbSymbolBits) == (nbSymbolBits - 1)) |
|
{ |
|
symbol = symbol ^ (symbol >> 1); // Gray code |
|
symbols.push_back(symbol); |
|
symbol = 0; |
|
} |
|
} |
|
} |
|
|
|
void MeshtasticModEncoderFT::encodeTextMsg(const QString& text, int a174[]) |
|
{ |
|
int a77[77]; |
|
std::fill(a77, a77 + 77, 0); |
|
QString sentMsg = text.rightJustified(13, ' ', true); |
|
|
|
if (!FT8::Packing::packfree(a77, sentMsg.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeTextMsg: failed to encode free text message (%s)", qPrintable(sentMsg)); |
|
return; |
|
} |
|
|
|
FT8::FT8::encode(a174, a77); |
|
} |
|
|
|
void MeshtasticModEncoderFT::encodeMsgBeaconOrCQ(const QString& myCall, const QString& myLocator, const QString& shorthand, int a174[]) |
|
{ |
|
int c28_1, c28_2, g15; |
|
|
|
if (!FT8::Packing::packcall_std(c28_1, shorthand.toUpper().toStdString())) // |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgBeaconOrCQ: failed to encode call1 (%s)", qPrintable(shorthand)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packcall_std(c28_2, myCall.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgBeaconOrCQ: failed to encode call2 (%s)", qPrintable(myCall)); |
|
return; |
|
} |
|
|
|
if (myLocator.size() < 4) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgBeaconOrCQ: locator invalid (%s)", qPrintable(myLocator)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packgrid(g15, myLocator.left(4).toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgBeaconOrCQ: failed to encode locator (%s)", qPrintable(myLocator)); |
|
return; |
|
} |
|
|
|
int a77[77]; |
|
std::fill(a77, a77 + 77, 0); |
|
FT8::Packing::pack1(a77, c28_1, c28_2, g15, 0); |
|
FT8::FT8::encode(a174, a77); |
|
} |
|
|
|
void MeshtasticModEncoderFT::encodeMsgReply(const QString& myCall, const QString& urCall, const QString& myLocator, int a174[]) |
|
{ |
|
int c28_1, c28_2, g15; |
|
|
|
if (!FT8::Packing::packcall_std(c28_1, urCall.toUpper().toStdString())) // |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReply: failed to encode call1 (%s)", qPrintable(urCall)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packcall_std(c28_2, myCall.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReply: failed to encode call2 (%s)", qPrintable(myCall)); |
|
return; |
|
} |
|
|
|
if (myLocator.size() < 4) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReply: locator invalid (%s)", qPrintable(myLocator)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packgrid(g15, myLocator.left(4).toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReply: failed to encode locator (%s)", qPrintable(myLocator)); |
|
return; |
|
} |
|
|
|
int a77[77]; |
|
std::fill(a77, a77 + 77, 0); |
|
FT8::Packing::pack1(a77, c28_1, c28_2, g15, 0); |
|
FT8::FT8::encode(a174, a77); |
|
} |
|
|
|
void MeshtasticModEncoderFT::encodeMsgReport(const QString& myCall, const QString& urCall, const QString& myReport, int reply, int a174[]) |
|
{ |
|
int c28_1, c28_2, g15; |
|
|
|
if (!FT8::Packing::packcall_std(c28_1, urCall.toUpper().toStdString())) // |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReport: failed to encode call1 (%s)", qPrintable(urCall)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packcall_std(c28_2, myCall.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReport: failed to encode call2 (%s)", qPrintable(myCall)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packgrid(g15, myReport.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgReport: failed to encode report (%s)", qPrintable(myReport)); |
|
return; |
|
} |
|
|
|
int a77[77]; |
|
std::fill(a77, a77 + 77, 0); |
|
FT8::Packing::pack1(a77, c28_1, c28_2, g15, reply); |
|
FT8::FT8::encode(a174, a77); |
|
} |
|
|
|
void MeshtasticModEncoderFT::encodeMsgFinish(const QString& myCall, const QString& urCall, const QString& shorthand, int a174[]) |
|
{ |
|
int c28_1, c28_2, g15; |
|
|
|
if (!FT8::Packing::packcall_std(c28_1, urCall.toUpper().toStdString())) // |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgFinish: failed to encode call1 (%s)", qPrintable(urCall)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packcall_std(c28_2, myCall.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgFinish: failed to encode call2 (%s)", qPrintable(myCall)); |
|
return; |
|
} |
|
|
|
if (!FT8::Packing::packgrid(g15, shorthand.toUpper().toStdString())) |
|
{ |
|
qDebug("MeshtasticModEncoderFT::encodeMsgFinish: failed to encode shorthand (%s)", qPrintable(shorthand)); |
|
return; |
|
} |
|
|
|
int a77[77]; |
|
std::fill(a77, a77 + 77, 0); |
|
FT8::Packing::pack1(a77, c28_1, c28_2, g15, 0); |
|
FT8::FT8::encode(a174, a77); |
|
} |
|
|
|
void MeshtasticModEncoderFT::interleave174(int a174[]) |
|
{ |
|
// 174 = 2*3*29 |
|
int t174[174]; |
|
std::copy(a174, a174+174, t174); |
|
|
|
for (int i = 0; i < 174; i++) { |
|
a174[i] = t174[(i%6)*29 + (i%29)]; |
|
} |
|
} |
|
|
|
#endif // HAS_FT8
|
|
|