Skip to content

Commit

Permalink
added ft8
Browse files Browse the repository at this point in the history
  • Loading branch information
JvanKatwijk committed Jun 27, 2022
1 parent dc75719 commit c99a765
Show file tree
Hide file tree
Showing 16 changed files with 564 additions and 139 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,14 @@ The decoder has three control elements

* a file button for selecting a file where the received messages are stored.

Note: the decoder is experimental and will definitly not catch all transmitted messages.
Note: the decoder is experimental and will definitely not catch all transmitted messages.

![swradio-8](/swradio-ft8-widget.png?raw=true)

In the current version one can set a **callsign** and a **home grid**,
if these are set, the decoder will upload details to the PSKReporter,
so you can see yourself as monitor on the PSKreporter map.

-------------------------------------------------------------------------
a note on the weatherfax decoder
-------------------------------------------------------------------------
Expand Down
50 changes: 46 additions & 4 deletions decoders/ft8-decoder/ft8-decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
*/
#
#include <QFileDialog>
#include <QInputDialog>
#include "ft8-decoder.h"
#include "radio.h"
#include "pack-handler.h"
#include <QStandardItemModel>

#include "radio.h"

#define LOG_BASE 240
Expand All @@ -36,7 +36,8 @@
QSettings *settings) :
virtualDecoder (inRate, buffer),
myFrame (nullptr),
theProcessor (this, 20) {
theWriter (settings),
theProcessor (this, 20, &theWriter) {
ft8Settings = settings;
this -> mr = mr;
setupUi (&myFrame);
Expand Down Expand Up @@ -87,6 +88,11 @@
this, SLOT (set_spectrumWidth (int)));
connect (filesaveButton, SIGNAL (clicked ()),
this, SLOT (handle_filesaveButton ()));
connect (identityButton, SIGNAL (clicked ()),
this, SLOT (handle_identityButton ()));

show_pskStatus (theWriter. reporterReady ());
teller = 0;
}

ft8_Decoder::~ft8_Decoder () {
Expand Down Expand Up @@ -117,11 +123,15 @@ void ft8_Decoder::process (std::complex<float> z) {
inBuffer [inPointer ++] = z;
if (inPointer < toneLength / FRAMES_PER_TONE)
return;

inPointer = 0;
static int counter = 0;
if (++counter >= 100) {
counter = 0;
theWriter. sendMessages ();
}
int content = (FRAMES_PER_TONE - 1) * toneLength / FRAMES_PER_TONE;
int newAmount = toneLength / FRAMES_PER_TONE;

inPointer = 0;
//
// shift the inputBuffer to left
memmove (inputBuffer, &inputBuffer [newAmount],
Expand Down Expand Up @@ -408,3 +418,35 @@ int ft8_Decoder::tunedFrequency () {
return mr -> tunedFrequency ();
}

bool ft8_Decoder::pskReporterReady () {
return pskReady;
}

void ft8_Decoder::handle_identityButton () {
bool ok;
QString text = QInputDialog::getText (nullptr, tr ("your callsign"),
"enter your callsign",
QLineEdit::Normal, tr ("NL99999"), &ok);
if (ok) {
ft8Settings -> beginGroup ("ft8Settings");
ft8Settings -> setValue ("homeCall", text);
}
text = QInputDialog::getText (nullptr, tr ("your grid"),
"enter your grid",
QLineEdit::Normal, tr ("JO00aa"), &ok);
if (ok) {
ft8Settings -> setValue ("homeGrid", text);
}
ft8Settings -> endGroup ();
}

void ft8_Decoder::show_pskStatus (bool b) {
if (b)
pskStatus -> setStyleSheet ("QLabel {background-color : green}");
else
pskStatus -> setStyleSheet ("QLabel {background-color : red}");
}

void ft8_Decoder::print_statistics () {
}

9 changes: 8 additions & 1 deletion decoders/ft8-decoder/ft8-decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "ft8-constants.h"
#include "ldpc.h"
#include "ft8-processor.h"
#include "psk-writer.h"
typedef struct {
int index;
float value;
Expand All @@ -53,17 +54,19 @@ Q_OBJECT
void processBuffer (std::complex<float> *, int32_t);
void process (std::complex<float> z);
int tunedFrequency ();
bool pskReporterReady ();

private:
QFrame myFrame;
ldpc ldpcHandler;
reporterWriter theWriter;
ft8_processor theProcessor;
QSettings *ft8Settings;
RadioInterface *mr;
int32_t inputRate;
int32_t outputRate;
int32_t samplesperSymbol;

bool pskReady;
std::atomic<FILE*> filePointer;
void peakFinder (float *V, int begin, int end,
std::vector<costasValue> &cache);
Expand Down Expand Up @@ -100,12 +103,16 @@ Q_OBJECT
QStandardItemModel model;
void showText (const QStringList &);
QStringList theResults;
int teller;
void print_statistics ();
public slots:
void printLine (const QString &);
void show_pskStatus (bool);
private slots:
void set_maxIterations (int);
void set_spectrumWidth (int);
void handle_filesaveButton ();
void handle_identityButton ();
};

#endif
Expand Down
18 changes: 16 additions & 2 deletions decoders/ft8-decoder/ft8-decoder.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>532</width>
<height>249</height>
<width>445</width>
<height>302</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -59,6 +59,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="identityButton">
<property name="text">
<string>set identity</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="pskStatus">
<property name="text">
<string>psk status</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="filesaveButton">
<property name="text">
Expand Down
57 changes: 49 additions & 8 deletions decoders/ft8-decoder/ft8-processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,27 @@
#include "ldpc.h"
#include "pack-handler.h"
#include "ft8-processor.h"
#include "psk-writer.h"
#include <time.h>

ft8_processor::ft8_processor (ft8_Decoder *theDecoder,
int maxIterations):
ft8_processor::ft8_processor (ft8_Decoder *theDecoder,
int maxIterations,
reporterWriter *theWriter):
theCache (30),
freeSlots (nrBlocks) {

this -> theDecoder = theDecoder;
this -> maxIterations = maxIterations;
this -> maxIterations = maxIterations;
this -> theWriter = theWriter;
this -> blockToRead = 0;
this -> blockToWrite = 0;

running. store (false);
connect (this,
SIGNAL (printLine (const QString &)),
theDecoder,
SLOT (printLine (const QString &)));
connect (this, SIGNAL (show_pskStatus (bool)),
theDecoder, SLOT (show_pskStatus (bool)));
threadHandle = std::thread (&ft8_processor::run, this);
}

Expand Down Expand Up @@ -73,7 +77,6 @@ void ft8_processor::set_maxIterations (int n) {
maxIterations. store (n);
}


void insertString (char *target, int pos, const QString &s) {
for (int i = 0; s.toLatin1 (). data () [i] != 0; i ++)
target [pos + i] = s. toLatin1 (). data () [i];
Expand All @@ -84,6 +87,23 @@ QString s = QString::number (number);
insertString (target, pos, s);
}

void insert_2_Number (char *target, int pos, int number) {
QString s;
if ((number >= 100) || (number < 0)) {
insertString (target, pos, QString::number (number));
return;
}
if (number >= 10) {
s. push_back ('0' + number / 10);
s. push_back ('0' + number % 10);
insertString (target, pos, s);
return;
}
s. push_back (' ');
s. push_back ('0' + number);
insertString (target, pos, s);
}

QString makeLine (QString time,
int value, int freq,
QString message) {
Expand All @@ -96,7 +116,7 @@ int posTable [] = {0, 20, 30, 45, 75};
res [i] = ' ';

insertString (res, posTable [0], time);
insertNumber (res, posTable [1], value > 100 ? 101 : value);
insert_2_Number (res, posTable [1], value > 100 ? 101 : value);
insertNumber (res, posTable [2], freq);
insertString (res, posTable [3], message);
res [posTable [4]] = 0;
Expand All @@ -107,12 +127,14 @@ void ft8_processor::run () {
uint8_t ldpcBits [FT8_LDPC_BITS];
ldpc ldpcHandler;
int errors;

fprintf (stderr, "The processor gaat draaien\n");
usleep (1000000);
running. store (true);
while (running. load()) {
while (!usedSlots. tryAcquire (200))
if (!running. load ())
return;

// ldpcHandler. bp_decode (theBuffer [blockToRead]. log174,
// maxIterations. load (),
// ldpcBits, &errors);
Expand All @@ -136,19 +158,38 @@ int errors;
ldpcBits [i] = 0;

if (check_crc_bits (ldpcBits, 96)) {
// fprintf (stderr, "crc OK\n");
// crc is correct, unpack the message
QString res = unpackHandler. unpackMessage (ldpcBits);
if (res != "") {
showLine (theBuffer [blockToRead]. lineno,
theBuffer [blockToRead]. value,
theBuffer [blockToRead]. frequency,
res);
if (theWriter -> reporterReady ()) {
QStringList call = unpackHandler. extractCall (ldpcBits);
if (call. length () > 0) {
QString callIdent = call. at (0);
QString locator;
if (call. length () == 2)
locator = call. at (1);
int snr = theBuffer [blockToRead]. value;
int freq = theBuffer [blockToRead]. frequency + theDecoder -> tunedFrequency ();
theWriter -> addMessage (callIdent. toStdString (),
locator. toStdString (),
freq, snr);
}

}
}
}
// prepare for the next round
freeSlots. Release ();
blockToRead = (blockToRead + 1) % (nrBlocks);
}
}
}

void ft8_processor::print_statistics () {
}

void ft8_processor::showLine (int line, int val,
Expand Down
12 changes: 8 additions & 4 deletions decoders/ft8-decoder/ft8-processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,24 @@
#include "dl-cache.h"

class ft8_Decoder;
class reporterWriter;
#define nrBlocks 100

class ft8_processor: public QObject {
Q_OBJECT
public:
ft8_processor (ft8_Decoder *, int);
ft8_processor (ft8_Decoder *, int, reporterWriter *);
~ft8_processor ();

void PassOn (int, float, int, float *);
void set_maxIterations (int);

private:
packHandler unpackHandler;
void run ();
bool check_crc_bits (uint8_t *message, int nrBits);
void showLine (int, int, int, const QString &);
reporterWriter *theWriter;
void run ();
bool check_crc_bits (uint8_t *message, int nrBits);
void showLine (int, int, int, const QString &);
dlCache theCache;
struct {
int lineno;
Expand All @@ -71,8 +73,10 @@ Q_OBJECT
std::thread threadHandle;
uint8_t a91 [FT8_M_BYTES];

void print_statistics ();
signals:
void printLine (const QString &);
void show_pskStatus (bool);
};
#endif

8 changes: 4 additions & 4 deletions decoders/ft8-decoder/hashHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ void hashHandler::add_hash (uint32_t key,
h. key = key;
h. value = s;
hashTable. push_back (h);
fprintf (stderr, "adding %X %s\n",
key, s. toLatin1 (). data ());
// fprintf (stderr, "adding %X %s\n",
// key, s. toLatin1 (). data ());
}

QString hashHandler::lookup (uint32_t key) {
for (int i = 0; i < hashTable. size (); i ++)
if (hashTable. at (i). key == key)
return hashTable. at (i). value;
fprintf (stderr, "key %X not found\n", key);
// fprintf (stderr, "key %X not found\n", key);
return "<....>";
}

Expand Down Expand Up @@ -79,7 +79,7 @@ FILE *f = fopen (s. c_str (), "w");
return;

for (int i = 0; i < hashTable. size (); i ++)
fprintf (stderr, "<%X:%s>\n", hashTable. at (i). key,
fprintf (f, "<%X:%s>\n", hashTable. at (i). key,
hashTable. at (i). value. toLatin1 (). data ());
fclose (f);
}
Expand Down
Loading

0 comments on commit c99a765

Please sign in to comment.