summaryrefslogtreecommitdiff
path: root/map65/mainwindow.cpp
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-06-22 12:03:55 +0200
committerChristoph Berg <myon@debian.org>2026-06-22 12:03:55 +0200
commitde18fc13175a5bf0e2b48a042d2fc06e87c88d24 (patch)
treef517074cd603d30eb7ba7e2122d38051e4c1439c /map65/mainwindow.cpp
parentb76e8361909e47f0937d4a64a5a4cb5939f51eb7 (diff)
parentd83a420f0517d7fc47aeb288a6a0cf4891784fcc (diff)
Update upstream source from tag 'upstream/3.0.2+dfsg'
Update to upstream version '3.0.2+dfsg' with Debian dir 90381fe7be9f5ea84d9b16c9cccf200a3fbe138b
Diffstat (limited to 'map65/mainwindow.cpp')
-rw-r--r--map65/mainwindow.cpp1551
1 files changed, 1110 insertions, 441 deletions
diff --git a/map65/mainwindow.cpp b/map65/mainwindow.cpp
index cc444928..7a47d5b6 100644
--- a/map65/mainwindow.cpp
+++ b/map65/mainwindow.cpp
@@ -2,7 +2,10 @@
#include "mainwindow.h"
#include <fftw3.h>
#include <QDir>
+#include <QRegularExpression>
#include <QSettings>
+#include <QStandardPaths>
+#include <QStringList>
#include <QTimer>
#include <QToolTip>
#include "revision_utils.hpp"
@@ -19,15 +22,95 @@
#include "bandmap.h"
#include "txtune.h"
#include "sleep.h"
+#include "commons.h"
+#include "soundin.h"
#include <portaudio.h>
+#include <iostream>
#include <QApplication>
#include <QDebug>
#include <QDateTime>
+#include <QFile>
+#include <QTextStream>
+#include <QString>
+#include <QByteArray>
+
+//#include <io.h>
+#include <stdio.h>
+
+#include <cstdio>
+#include <cstdlib>
+#include <unistd.h> // for pipe(), dup2()
+#include <math.h>
+#include <thread>
+#include <fcntl.h>
+
+#include "stdout_channel.h"
+#include "fortran_mutex.hpp"
+
+#if !defined(Q_OS_WIN)
+extern "C" {
+ void ptt_set_override(const char *path);
+}
+#endif
+
+extern "C" {
+ int ptt_(int* nport, int* itx, int* iptt);
+}
+
+#ifdef __unix__
+extern "C" void ptt_close(void);
+#endif
+
+#ifdef MessageBox
+#undef MessageBox
+#endif
#define NFFT 32768
-short int iwave[2*60*12000]; //Wave file for Tx audio
+
+QByteArray g_TxTuneGeometry;
+
+namespace {
+struct Map65TxWaveStorage { short int samples[2*60*12000]; };
+struct Map65RxSamplesStorage { qint16 samples[4*60*96000]; };
+
+QString writableMap65DataDir()
+{
+ QString dataDir = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
+ if (dataDir.isEmpty()) {
+ dataDir = QDir::home().absoluteFilePath(".map65");
+ }
+
+ if (!QDir{}.mkpath(dataDir)) {
+ qWarning() << "Unable to create MAP65 data directory:" << dataDir;
+ }
+
+ QDir dir {dataDir};
+ if (!dir.mkpath("save")) {
+ qWarning() << "Unable to create MAP65 save directory:" << dir.absoluteFilePath("save");
+ }
+ return dataDir;
+}
+
+QString map65SettingsFile(QString const& appDir, QString const& dataDir)
+{
+ QString settingsFile = QDir {dataDir}.absoluteFilePath("map65.ini");
+ QString legacySettingsFile = QDir {appDir}.absoluteFilePath("map65.ini");
+ if (!QFile::exists(settingsFile) && QFile::exists(legacySettingsFile)) {
+ if (QFile::copy(legacySettingsFile, settingsFile)) {
+ QFile::setPermissions(settingsFile, QFile::ReadOwner | QFile::WriteOwner
+ | QFile::ReadGroup | QFile::ReadOther);
+ } else {
+ qWarning() << "Unable to migrate MAP65 settings from" << legacySettingsFile
+ << "to" << settingsFile;
+ }
+ }
+ return settingsFile;
+}
+} // namespace
+
+short int (&iwave)[2*60*12000] = (new Map65TxWaveStorage{})->samples; //Wave file for Tx audio
int nwave; //Length of Tx waveform
bool btxok; //True if OK to transmit
bool bTune;
@@ -36,35 +119,95 @@ double outputLatency; //Latency in seconds
int txPower;
int iqAmp;
int iqPhase;
-qint16 id[4*60*96000];
+qint16 (&id)[4*60*96000] = (new Map65RxSamplesStorage{})->samples;
+int pipefd[2]; // pipefd[0] = read end, pipefd[1] = write end
TxTune* g_pTxTune = NULL;
-QSharedMemory mem_m65("mem_m65");
extern const int RxDataFrequency = 96000;
extern const int TxDataFrequency = 11025;
+std::atomic<bool> stop_m65{false};
+
QString guiDate; //liveCQ
QStringList allDecodes; //liveCQ
QStringList allDecodes2; //liveCQ
QString m_otherUrl;
bool m_w3szUrl;
bool m_spot_to_psk_reporter;
+bool m_psk_reporter_tcpip;
+
+struct MainWindow::DecoderContext
+{
+ StdoutChannel* stdoutChan;
+ DecoderContext();
+ ~DecoderContext();
+};
+
+MainWindow::DecoderContext::DecoderContext()
+{
+ stdoutChan = new StdoutChannel(
+ L"MAP65_STDOUT_MAPPING",
+ L"MAP65_STDOUT_EVENT",
+ 64 * 1024
+ );
+}
+
+MainWindow::DecoderContext::~DecoderContext()
+{
+ delete stdoutChan;
+}
//-------------------------------------------------- MainWindow constructor
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),
m_appDir {QApplication::applicationDirPath ()},
- m_settings_filename {m_appDir + "/map65.ini"},
+ m_dataDir {writableMap65DataDir ()},
+ m_settings_filename {map65SettingsFile (m_appDir, m_dataDir)},
m_astro_window {new Astro {m_settings_filename}},
m_band_map_window {new BandMap {m_settings_filename}},
m_messages_window(nullptr),
m_wide_graph_window {new WideGraph {m_settings_filename}},
m_gui_timer {new QTimer {this}}
{
+ qDebug() << "IN MainWindow Constructor NFFT IS: " << NFFT;
+ // Legacy C++ and Fortran paths still use relative opens for runtime files.
+ if (!QDir::setCurrent(m_dataDir)) {
+ qWarning() << "Unable to set MAP65 working directory:" << m_dataDir;
+ }
+ constexpr int baseSeconds = 56;
+ constexpr int sampleRate = 96000;
+ constexpr int channels = 4; // dd(1..4, t)
+
+ decoderCtx = new DecoderContext();
+ startSharedMemoryStdoutReader(decoderCtx);
+
+ // Worst-case: xpol = true ? 2 * baseSeconds * sampleRate I/Q pairs
+ const int pairsWorst = 2 * baseSeconds * sampleRate;
+ const int ddSize = pairsWorst * channels;
+ this->ddSize = ddSize;
+ dd = new float[ddSize];
+
+ // Tell Fortran about the maximum shape (channels × pairsWorst)
+ set_dd_ptr(dd, channels, pairsWorst);
+
+ std::cout << "dd pointer set to: " << dd
+ << " size: " << ddSize
+ << " (channels=" << channels
+ << ", pairsWorst=" << pairsWorst << ")\n";
+
+ ss = new float[4 * 322 * NFFT];
+ savg = new float[4 * NFFT];
+ set_ss_ptr(ss, 4, 322, NFFT);
+ std::cout << "ss pointer set to: " << ss << std::endl;
+ set_savg_ptr(savg, 4, NFFT);
+ std::cout << "savg pointer set to: " << savg << std::endl;
+
+ qDebug() << "MAINWINDOW created dd ss savg ";
+
ui->setupUi(this);
- on_EraseButton_clicked();
+// on_EraseButton_clicked(); //placing this here is a bug that will sometimes produce a crash on startup.
ui->labUTC->setStyleSheet( \
"QLabel { background-color : black; color : yellow; }");
ui->labTol1->setStyleSheet( \
@@ -108,11 +251,100 @@ MainWindow::MainWindow(QWidget *parent) :
txMsgButtonGroup->addButton(ui->txrb4,4);
txMsgButtonGroup->addButton(ui->txrb5,5);
txMsgButtonGroup->addButton(ui->txrb6,6);
- connect(txMsgButtonGroup,SIGNAL(buttonClicked(int)),SLOT(set_ntx(int)));
+ connect(txMsgButtonGroup,
+ QOverload<QAbstractButton *>::of(&QButtonGroup::buttonClicked),
+ this,
+ [this, txMsgButtonGroup](QAbstractButton *btn) {
+ int id = txMsgButtonGroup->id(btn);
+ set_ntx(id);
+ });
+
connect(ui->decodedTextBrowser,SIGNAL(selectCallsign(bool)),this,
SLOT(selectCall2(bool)));
+ // Callsign-overlay toggle (N6NU 2026-05-12, port of QMAP feature).
+ // View menu action ↔ WideGraph state, two-way mirror via signal.
+ if (m_wide_graph_window) {
+ ui->actionShow_callsigns_on_Waterfall->setChecked(
+ m_wide_graph_window->decodeLabelsEnabled());
+ connect(ui->actionShow_callsigns_on_Waterfall, &QAction::toggled,
+ m_wide_graph_window.data(), &WideGraph::setDecodeLabelsEnabled);
+ connect(m_wide_graph_window.data(), &WideGraph::decodeLabelsEnabledChanged,
+ ui->actionShow_callsigns_on_Waterfall, &QAction::setChecked);
+
+ // Decoded-callsign overlay transparency — exclusive action group
+ // (View → Callsign transparency). None=255 / Low=220 / Medium=200 /
+ // High=175. Persisted under [WideGraph]/decode_label_alpha.
+ QActionGroup* transparencyGroup = new QActionGroup(this);
+ ui->actionTransparency_None ->setActionGroup(transparencyGroup);
+ ui->actionTransparency_Low ->setActionGroup(transparencyGroup);
+ ui->actionTransparency_Medium->setActionGroup(transparencyGroup);
+ ui->actionTransparency_High ->setActionGroup(transparencyGroup);
+ {
+ const int a = m_wide_graph_window->decodeLabelAlpha();
+ if (a == 175) ui->actionTransparency_High ->setChecked(true);
+ else if (a == 200) ui->actionTransparency_Medium->setChecked(true);
+ else if (a == 220) ui->actionTransparency_Low ->setChecked(true);
+ else ui->actionTransparency_None ->setChecked(true);
+ }
+ auto* wg = m_wide_graph_window.data();
+ connect(ui->actionTransparency_None, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelAlpha(255); });
+ connect(ui->actionTransparency_Low, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelAlpha(220); });
+ connect(ui->actionTransparency_Medium, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelAlpha(200); });
+ connect(ui->actionTransparency_High, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelAlpha(175); });
+
+ // Decoded-callsign overlay font-size — exclusive action group
+ // (View → Callsign font size). Small=7 / Normal=8 (default) /
+ // Medium=10 / Large=12. Persisted via WideGraph::setDecodeLabelFontSize.
+ QActionGroup* fontGroup = new QActionGroup(this);
+ ui->actionCallsign_font_small ->setActionGroup(fontGroup);
+ ui->actionCallsign_font_normal->setActionGroup(fontGroup);
+ ui->actionCallsign_font_medium->setActionGroup(fontGroup);
+ ui->actionCallsign_font_large ->setActionGroup(fontGroup);
+ switch (wg->decodeLabelFontSize()) {
+ case DecodeLabelFontSize::Small:
+ ui->actionCallsign_font_small ->setChecked(true); break;
+ case DecodeLabelFontSize::Medium:
+ ui->actionCallsign_font_medium->setChecked(true); break;
+ case DecodeLabelFontSize::Large:
+ ui->actionCallsign_font_large ->setChecked(true); break;
+ case DecodeLabelFontSize::Normal:
+ default:
+ ui->actionCallsign_font_normal->setChecked(true); break;
+ }
+ connect(ui->actionCallsign_font_small, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelFontSize(DecodeLabelFontSize::Small); });
+ connect(ui->actionCallsign_font_normal, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelFontSize(DecodeLabelFontSize::Normal); });
+ connect(ui->actionCallsign_font_medium, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelFontSize(DecodeLabelFontSize::Medium); });
+ connect(ui->actionCallsign_font_large, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelFontSize(DecodeLabelFontSize::Large); });
+
+ // Callsign-overlay anchor position. Top (legacy) or Bottom (sit
+ // above the divider so fresh signals at the top of the waterfall
+ // remain visible). Persisted under [WideGraph]/decode_label_position
+ // via WideGraph::setDecodeLabelPosition.
+ QActionGroup* positionGroup = new QActionGroup(this);
+ ui->actionCallsign_position_top ->setActionGroup(positionGroup);
+ ui->actionCallsign_position_bottom->setActionGroup(positionGroup);
+ if (wg->decodeLabelPosition() == DecodeLabelPosition::Bottom) {
+ ui->actionCallsign_position_bottom->setChecked(true);
+ } else {
+ ui->actionCallsign_position_top ->setChecked(true);
+ }
+ connect(ui->actionCallsign_position_top, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelPosition(DecodeLabelPosition::Top); });
+ connect(ui->actionCallsign_position_bottom, &QAction::triggered,
+ wg, [wg]{ wg->setDecodeLabelPosition(DecodeLabelPosition::Bottom); });
+ }
+
setWindowTitle (program_title ());
+ qDebug() << "MAINWINDOW about to start soundInThread SIGNAL/SLOT connections";
connect(&soundInThread, SIGNAL(readyForFFT(int)),
this, SLOT(dataSink(int)));
@@ -121,19 +353,9 @@ MainWindow::MainWindow(QWidget *parent) :
connect(&soundInThread, SIGNAL(status(QString)), this,
SLOT(showStatusMessage(QString)));
createStatusBar();
+ qDebug() << "MAINWINDOW created soundInThread SIGNAL/SLOT connections";
- connect(&proc_m65, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()));
- connect(&proc_m65, &QProcess::errorOccurred, this, &MainWindow::m65_error);
- connect(&proc_m65, static_cast<void (QProcess::*) (int, QProcess::ExitStatus)> (&QProcess::finished),
- [this] (int exitCode, QProcess::ExitStatus status) {
- if (subProcessFailed (&proc_m65, exitCode, status))
- {
- QTimer::singleShot (0, this, SLOT (close ()));
- }
- });
-
- connect(&proc_editor, SIGNAL(error(QProcess::ProcessError)),
- this, SLOT(editor_error()));
+ connect(&proc_editor, &QProcess::errorOccurred, this, &MainWindow::editor_error);
connect(m_gui_timer, &QTimer::timeout, this, &MainWindow::guiUpdate);
@@ -149,13 +371,12 @@ MainWindow::MainWindow(QWidget *parent) :
m_ntx=1;
m_myCall="K1JT";
m_myGrid="FN20qi";
- m_saveDir="/users/joe/map65/install/save";
- m_azelDir="/users/joe/map65/install/";
+ m_saveDir=QDir {m_dataDir}.absoluteFilePath("save");
+ m_azelDir=m_dataDir;
m_editorCommand="notepad";
m_txFreq=125;
m_setftx=0;
m_loopall=false;
- m_startAnother=false;
m_saveAll=false;
m_onlyEME=false;
m_sec0=-1;
@@ -187,42 +408,16 @@ MainWindow::MainWindow(QWidget *parent) :
ySignalMeter = new SignalMeter(ui->yMeterFrame);
ySignalMeter->resize(50, 160);
-#ifdef WIN32
- while(true) {
- int iret=killbyname("m65.exe");
- if(iret == 603) break;
- if(iret != 0) msgBox("KillByName return code: " +
- QString::number(iret));
- }
-#endif
-
- if(!mem_m65.attach()) {
- if (!mem_m65.create(sizeof(datcom_))) {
- msgBox("Unable to create shared memory segment.");
- }
- }
- char *to = (char*)mem_m65.data();
- int size=sizeof(datcom_);
- if(datcom_.newdat==0) {
- int noffset = 4*4*5760000 + 4*4*322*32768 + 4*4*32768;
- to += noffset;
- size -= noffset;
- }
- memset(to,0,size); //Zero all decoding params in shared memory
-
- fftwf_import_wisdom_from_filename (QDir {m_appDir}.absoluteFilePath ("map65_wisdom.dat").toLocal8Bit ());
+ fftwf_import_wisdom_from_filename (QDir {m_dataDir}.absoluteFilePath ("map65_wisdom.dat").toLocal8Bit ());
+ readSettings(); //Restore user's setup params
PaError paerr=Pa_Initialize(); //Initialize Portaudio
if(paerr!=paNoError) {
msgBox("Unable to initialize PortAudio.");
}
- readSettings(); //Restore user's setup params
- QFile lockFile(m_appDir + "/.lock"); //Create .lock so m65 will wait
- lockFile.open(QIODevice::ReadWrite);
- QFile quitFile(m_appDir + "/.quit");
+ QFile quitFile(QDir {m_dataDir}.absoluteFilePath (".quit"));
quitFile.remove();
- proc_m65.start(QDir::toNativeSeparators(m_appDir + "/m65"), {"-s", });
-
+
m_pbdecoding_style1="QPushButton{background-color: cyan; \
border-style: outset; border-width: 1px; border-radius: 5px; \
border-color: black; min-width: 5em; padding: 3px;}";
@@ -237,8 +432,8 @@ MainWindow::MainWindow(QWidget *parent) :
on_actionAstro_Data_triggered(); //Create the other windows
on_actionWide_Waterfall_triggered();
-
on_actionBand_Map_triggered();
+
m_band_map_window->setColors(m_colors);
if (m_astro_window) m_astro_window->setFontSize (m_astroFont);
@@ -256,6 +451,8 @@ MainWindow::MainWindow(QWidget *parent) :
future1 = new QFuture<void>;
watcher1 = new QFutureWatcher<void>;
connect(watcher1, SIGNAL(finished()),this,SLOT(diskDat()));
+ bool ok = connect(watcher1, SIGNAL(finished()), this, SLOT(onDiskDecodeFinished()));
+ qDebug() << "onDiskDecodeFinished watcher connected" << ok;
future2 = new QFuture<void>;
watcher2 = new QFutureWatcher<void>;
@@ -278,8 +475,6 @@ MainWindow::MainWindow(QWidget *parent) :
m_monitoring=true; // Start with Monitoring ON
soundInThread.setMonitoring(m_monitoring);
m_diskData=false;
- m_tol=500;
- m_wide_graph_window->setTol(m_tol);
m_wide_graph_window->setFcal(m_fCal);
if(m_fs96000) m_wide_graph_window->setFsample(96000);
if(!m_fs96000) m_wide_graph_window->setFsample(95238);
@@ -291,7 +486,7 @@ MainWindow::MainWindow(QWidget *parent) :
// Create "m_worked", a dictionary of all calls in wsjt.log
QFile f("wsjt.log");
- f.open(QIODevice::ReadOnly);
+ qDebug() << "MainWindow Constructor File open result:" << f.open(QFileDevice::ReadOnly);
if(f.isOpen()) {
QTextStream in(&f);
QString line,t,callsign;
@@ -321,19 +516,42 @@ MainWindow::MainWindow(QWidget *parent) :
if (m_messages_window) m_messages_window->setColors(m_colors);
});
+ QTimer::singleShot (2000, [=] {
+ setNhsym(1);
+ });
+ QTimer::singleShot (4000, [=] {
+ qDebug() << "MAINWINDOW reads Fortran fcenter as: " << getFcenter();
+ });
+
//default freq at startup for Doppler and Tsky
- datcom_.fcenter = m_wide_graph_window->m_dForceCenterFreq;
- if(datcom_.fcenter == 0) datcom_.fcenter = 144.125;
+ setFcenter(m_wide_graph_window->m_dForceCenterFreq);
+ if( getFcenter() == 0) setFcenter(144.125);
+ qDebug() << "MAINWINDOW reached end of Constructor";
// only start the guiUpdate timer after this constructor has finished
QTimer::singleShot (0, [=] {
m_gui_timer->start(100); //Don't change the 100 ms!
});
+
+ // Start Run_m65
+ QTimer::singleShot(0, this, SLOT(startDecoder()));
}
//--------------------------------------------------- MainWindow destructor
MainWindow::~MainWindow()
{
+ // Stop stdout reader thread
+ stdoutReaderStop.store(true);
+
+ // Wake event so thread exits immediately
+ if (decoderCtx && decoderCtx->stdoutChan) {
+ void* ev = decoderCtx->stdoutChan->eventHandle;
+ if (ev)
+ win_set_event(ev);
+ }
+
+ if (stdoutReaderThread.joinable())
+ stdoutReaderThread.join();
writeSettings();
if (soundInThread.isRunning()) {
soundInThread.quit();
@@ -344,14 +562,312 @@ MainWindow::~MainWindow()
soundOutThread.wait(3000);
}
Pa_Terminate();
- fftwf_export_wisdom_to_filename (QDir {m_appDir}.absoluteFilePath ("map65_wisdom.dat").toLocal8Bit ());
- if(!m_decoderBusy) {
- QFile lockFile(m_appDir + "/.lock");
- lockFile.remove();
- }
+ fftwf_export_wisdom_to_filename (QDir {m_dataDir}.absoluteFilePath ("map65_wisdom.dat").toLocal8Bit ());
delete ui;
}
+void MainWindow::startDecoder()
+{
+ qDebug() << "MAINWINDOW calling run_m65_ ";
+
+ QByteArray runtimeDir = QDir::toNativeSeparators(m_dataDir).toLocal8Bit();
+ set_wsjtx_dir_(runtimeDir.constData(), runtimeDir.size());
+
+ QFutureWatcher<void>* watcher_m65 = new QFutureWatcher<void>(this);
+ connect(watcher_m65, &QFutureWatcher<void>::finished,
+ this, &MainWindow::onRunM65Finished);
+
+ watcher_m65->setFuture(QtConcurrent::run([=]() {
+ // Hook up shared stdout channel for Fortran
+ StdoutSharedRegion* region =
+ decoderCtx->stdoutChan->shared.getRegion();
+
+ void* bufPtr = static_cast<void*>(region->buffer);
+ void* hdrPtr = static_cast<void*>(&region->header);
+ int bufSize = static_cast<int>(decoderCtx->stdoutChan->shared.getBufferSize());
+ intptr_t eventH = reinterpret_cast<intptr_t>(decoderCtx->stdoutChan->eventHandle);
+
+ set_stdout_channel(bufPtr, hdrPtr, bufSize, eventH);
+
+ // Now run the decoder
+ std::lock_guard<std::mutex> lock(g_fortran_decode_mutex);
+ int xpol_flag = m_xpol ? 1 : 0;
+ int rate_flag = m_fs96000 ? 1 : 0;
+ run_m65_(&xpol_flag, &rate_flag);
+
+ }));
+}
+
+void MainWindow::startSharedMemoryStdoutReader(DecoderContext* ctx)
+{
+ stdoutReaderThread = std::thread([this, ctx]() {
+
+ StdoutSharedRegion* region =
+ ctx->stdoutChan->shared.getRegion();
+
+ char* bufferBase =
+ reinterpret_cast<char*>(region->buffer);
+
+ std::size_t bufSize =
+ ctx->stdoutChan->shared.getBufferSize();
+
+ // Linux: eventHandle is a void* pointing to posix_event_t
+ void* ev = ctx->stdoutChan->eventHandle;
+
+ // NEW: start reading from the current writeIndex
+ StdoutSharedHeader h0 = region->header;
+ std::uint32_t readIndex = h0.writeIndex;
+ if (readIndex >= bufSize)
+ readIndex = 0;
+
+ std::string lineBuffer;
+
+ while (!stdoutReaderStop.load()) {
+
+ // Linux replacement for WaitForSingleObject(ev, INFINITE)
+ win_wait_for_single_object(ev);
+
+ // After wakeup, read new data
+ StdoutSharedHeader h = region->header;
+ std::uint32_t writeIndex = h.writeIndex;
+ if (writeIndex >= bufSize)
+ writeIndex = 0;
+
+ while (readIndex != writeIndex) {
+ char c = bufferBase[readIndex];
+ readIndex++;
+ if (readIndex >= bufSize)
+ readIndex = 0;
+
+ lineBuffer.push_back(c);
+ if (c == '\n') {
+ std::string line = lineBuffer;
+ lineBuffer.clear();
+
+ QString text = QString::fromStdString(line);
+ QMetaObject::invokeMethod(
+ this,
+ [this, text]() { processStdOut(text); },
+ Qt::QueuedConnection
+ );
+ }
+ }
+ }
+
+ });
+}
+
+void MainWindow::processStdOut(QString t)
+{
+
+// qDebug().noquote() << QDateTime::currentMSecsSinceEpoch() << "PROCESS STDOUT:" << t;
+
+ //qDebug() << "in processStdOut STDOUT:" << t;
+if (t.indexOf("<QuickDecodeDone>") >= 0) {
+
+ // Any decoder output means "not idle" — reset idle timer in auto/disk mode
+
+ m_nsum = t.mid(17,4).toInt();
+ m_nsave = t.mid(21,4).toInt();
+ lab7->setText(QString{"Avg: %1"}.arg(m_nsum));
+ if (m_modeQ65 > 0)
+ m_wide_graph_window->setDecodeFinished();
+ }
+
+ // --- <EarlyFinished> / <DecodeFinished> ---
+ if (t.indexOf("<EarlyFinished>") >= 0 || t.indexOf("<DecodeFinished>") >= 0) {
+
+ if (m_widebandDecode) {
+ if (m_messages_window)
+ m_messages_window->setText(m_messagesText, m_bandmapText);
+ if (m_band_map_window)
+ m_band_map_window->setText(m_bandmapText);
+ m_widebandDecode = false;
+ }
+ if (t.indexOf("<DecodeFinished>") >= 0) {
+ ++m_decodeFinishedCount;
+
+ decodeBusy(false);
+// qDebug().noquote() << QDateTime::currentMSecsSinceEpoch() << "decodeBusy(false)";
+ if (m_diskData) onDiskDecodeFinished();
+
+ int ndecodes = t.mid(40,5).toInt();
+ lab5->setText(QString::number(ndecodes));
+ m_map65RxLog = 0;
+ }
+
+ ui->DecodeButton->setStyleSheet("");
+ return;
+}
+
+ // --- same position as legacy ---
+ read_log();
+
+ // --- "!" decoded text lines ---
+ if (t.startsWith("!")) {
+ int n = t.length();
+ int m = 2;
+#ifdef WIN32
+ m = 3;
+#endif
+ const QString decode_line = t.mid(1, n - m);
+
+ // Suppress *second* narrowband GUI entry, but keep everything else
+ if (m_RxState != 2 || m_diskData) {
+ if (n >= 30 || t.indexOf("Best-fit") >= 0)
+ ui->decodedTextBrowser->append(decode_line);
+ }
+
+ int max = ui->decodedTextBrowser->verticalScrollBar()->maximum();
+ ui->decodedTextBrowser->verticalScrollBar()->setValue(max);
+
+ // Callsign-overlay tap (N6NU 2026-05-13, DG2YCB feedback round 4).
+ // Two stdout-write paths for decodes (q65b.f90:227, map65a.f90:430)
+ // share enough format that we can parse them together:
+ // JT65: ("!",I3,I5,I4,I6.4,F5.1,I5,1X,A1,1X,A22,I2,I5,I5,1X,A1)
+ // Q65 : ("!",I3.3,I5,I4,I6.4,F5.1,I5," : ",A28,A3,I4,1X,A1)
+ // The Q65 line is the only one that contains a literal " : " — use
+ // that as the mode discriminator (right(2) does NOT work: both
+ // lines end in 1X+A1 = " cp", just a single status char).
+ //
+ // Q65 stdout writes are guarded by an in-tolerance-of-mouse check
+ // (q65b.f90:226), so most off-target Q65 decodes never reach this
+ // tap. The "&" bandmap handler below covers them as a fallback.
+ if (m_wide_graph_window) {
+ const QString trimmed = decode_line.trimmed();
+ const int sep = decode_line.indexOf(" : ");
+ const bool is_jt65 = (sep < 0); // " : " present ⇒ Q65
+
+ // The "!" decode line packs the audio frequency into TWO
+ // columns per the Fortran writes at map65a.f90:387 and
+ // q65b.f90:227 — format ("!",I3,I5,...) where nkHz is the
+ // integer kHz and ndf is the signed delta-Hz within that
+ // kHz, so true freq = nkHz + ndf/1000.0. The previous
+ // "first token that parses as a number in [0,1e6)" approach
+ // dropped ndf (off by ±500 Hz for small nkHz) or worse,
+ // picked ndf itself when nkHz ≥ 100 made the right-
+ // justified I3 collide with the leading "!" (the parser
+ // then read ndf in Hz as kHz).
+ QString rest = trimmed;
+ if (rest.startsWith('!')) rest = rest.mid(1);
+ const QStringList all_cols = rest.split(
+ QRegularExpression("\\s+"),SkipEmptyParts);
+ double freq_khz = -1.0;
+ if (all_cols.size() >= 2) {
+ bool ok1 = false, ok2 = false;
+ const int nkHz = all_cols[0].toInt(&ok1);
+ const int ndf = all_cols[1].toInt(&ok2);
+ if (ok1 && ok2) freq_khz = nkHz + ndf / 1000.0;
+ }
+
+ QString body;
+ if (sep > 0) {
+ body = decode_line.mid(sep + 3).trimmed();
+ } else if (decode_line.size() > 31) {
+ body = decode_line.mid(31).trimmed();
+ }
+ const QStringList msg_cols = body.split(
+ QRegularExpression("\\s+"),SkipEmptyParts);
+ QString sender;
+ if (msg_cols.size() >= 2) {
+ if (msg_cols[0] == "CQ") {
+ if (msg_cols.size() >= 3 && msg_cols[1] == "DX") sender = msg_cols[2];
+ else sender = msg_cols[1];
+ } else {
+ sender = msg_cols[1]; // directed: TO_call FROM_call
+ }
+ }
+ static const QRegularExpression call_re(
+ "^[A-Z0-9]{1,3}[0-9][A-Z0-9]{0,3}[A-Z](/[A-Z0-9]+)?$");
+ if (freq_khz > 0 && !sender.isEmpty()
+ && call_re.match(sender.toUpper()).hasMatch()) {
+ m_wide_graph_window->addDecodeLabel(freq_khz, sender, is_jt65);
+ }
+ }
+
+ // clear snapshots for this decode run, just like legacy
+ m_messagesText.clear();
+ m_bandmapText.clear();
+ }
+
+ // --- "@" message lines ---
+ if (t.startsWith("@")) {
+ m_messagesText += t.mid(1);
+ m_widebandDecode = true;
+ }
+
+ // --- "&" bandmap lines ---
+ // N6NU 2026-05-24: format widened to include the 5-char ndf from
+ // line3(k)(9:13). New layout:
+ // "&" + I3 kHz + I5 ndf + " " + A6 call + A2 age
+ // Old layout (pre-260524, used by stock map65):
+ // "&" + I3 kHz + " " + A6 call + A2 age
+ // We auto-detect by checking column 4: if it's a digit/space-of-int,
+ // it's the new format. Old format has the space-separator there.
+ if (t.startsWith("&")) {
+ // Detect format. New: chars 4..8 are an int (ndf). Old: char 4
+ // is a space and chars 5..10 are the callsign.
+ const QString ndf_field = t.mid(4, 5);
+ bool ndf_ok = false;
+ const int ndf_hz = ndf_field.trimmed().toInt(&ndf_ok);
+ const int call_start = ndf_ok ? 10 : 5;
+
+ QString q(t);
+ QString callsign = q.mid(call_start);
+ callsign = callsign.mid(0, callsign.indexOf(" "));
+ if (callsign.length() > 2) {
+ if (m_worked[callsign]) {
+ q = q.mid(1,4) + " " + q.mid(call_start);
+ } else {
+ q = q.mid(1,4) + " *" + q.mid(call_start);
+ }
+ m_bandmapText += q;
+
+ // Fallback overlay tap (N6NU 2026-05-13, DG2YCB feedback r4).
+ // We can't know the mode from this line, so pass is_jt65=false
+ // and mode_reliable=false. With the new format we now also
+ // have ndf precision, so freq_reliable=true. Old format
+ // callers still pass freq_reliable=false (integer kHz only).
+ if (m_wide_graph_window) {
+ bool ok_khz = false;
+ const int nkHz = t.mid(1, 3).trimmed().toInt(&ok_khz);
+ const double freq_khz = ndf_ok
+ ? (nkHz + ndf_hz / 1000.0)
+ : double(nkHz);
+ static const QRegularExpression call_re(
+ "^[A-Z0-9]{1,3}[0-9][A-Z0-9]{0,3}[A-Z](/[A-Z0-9]+)?$");
+ if (ok_khz && freq_khz > 0
+ && call_re.match(callsign.toUpper()).hasMatch()) {
+ m_wide_graph_window->addDecodeLabel(
+ freq_khz, callsign, /*is_jt65=*/false,
+ /*mode_reliable=*/false,
+ /*freq_reliable=*/ndf_ok);
+ }
+ }
+ }
+ }
+
+ // --- "=" debug lines ---
+ if (t.startsWith("=")) {
+ int n = t.size();
+ qDebug() << t.mid(1, n - 3).trimmed();
+ }
+ // --- END OF processStdOut ---
+}
+
+void MainWindow::onRunM65Finished() {
+ // Do something when run_m65 finishes
+}
+
+void MainWindow::onDiskDecodeFinished()
+{
+ if (!m_path.isEmpty())
+ setWindowTitle("MAP65 - " + QFileInfo(m_path).fileName());
+
+ if (m_loopall)
+ on_actionOpen_next_in_directory_triggered();
+}
+
//-------------------------------------------------------- writeSettings()
void MainWindow::writeSettings()
{
@@ -365,11 +881,13 @@ void MainWindow::writeSettings()
settings.setValue("DXgrid",ui->dxGridEntry->text());
}
+ {
SettingsGroup g {&settings, "Common"};
settings.setValue("MyCall",m_myCall);
settings.setValue("MyGrid",m_myGrid);
settings.setValue("IDint",m_idInt);
- settings.setValue("PTTport",m_pttPort);
+ settings.setValue("PTTpath",m_pttPath);
+ settings.setValue("PTTPortNumber",m_pttPortNumber);
settings.setValue("AstroFont",m_astroFont);
settings.setValue("Xpol",m_xpol);
settings.setValue("XpolX",m_xpolx);
@@ -378,9 +896,6 @@ void MainWindow::writeSettings()
settings.setValue("Editor",m_editorCommand);
settings.setValue("DXCCpfx",m_dxccPfx);
settings.setValue("Timeout",m_timeout);
- settings.setValue("TxPower",txPower);
- settings.setValue("IQamp",iqAmp);
- settings.setValue("IQphase",iqPhase);
settings.setValue("ApplyIQcal",m_applyIQcal);
settings.setValue("dPhi",m_dPhi);
settings.setValue("Fcal",m_fCal);
@@ -424,6 +939,19 @@ void MainWindow::writeSettings()
settings.setValue("w3szUrl",m_w3szUrl); //liveCQ
settings.setValue("otherUrl",m_otherUrl); //liveCQ
settings.setValue("spotPSK",m_spot_to_psk_reporter);
+ settings.setValue("PSKReporterTCPIP",m_psk_reporter_tcpip);
+ settings.setValue("FTol",m_tol);
+ settings.endGroup();
+ }
+
+ {
+ settings.beginGroup("TxTune");
+ settings.setValue("geometry", g_TxTuneGeometry);
+ settings.setValue("TxPower",txPower);
+ settings.setValue("IQamp",iqAmp);
+ settings.setValue("IQphase",iqPhase);
+ settings.endGroup();
+ }
}
//---------------------------------------------------------- readSettings()
@@ -435,33 +963,35 @@ void MainWindow::readSettings()
restoreGeometry(settings.value("geometry").toByteArray());
ui->dxCallEntry->setText(settings.value("DXcall","").toString());
ui->dxGridEntry->setText(settings.value("DXgrid","").toString());
- m_path = settings.value("MRUdir", m_appDir + "/save").toString();
+ m_path = settings.value("MRUdir", QDir {m_dataDir}.absoluteFilePath("save")).toString();
m_txFirst = settings.value("TxFirst",false).toBool();
ui->txFirstCheckBox->setChecked(m_txFirst);
}
+ {
SettingsGroup g {&settings, "Common"};
m_myCall=settings.value("MyCall","").toString();
m_myGrid=settings.value("MyGrid","").toString();
m_idInt=settings.value("IDint",0).toInt();
- m_pttPort=settings.value("PTTport",0).toInt();
+ m_pttPath=settings.value("PTTpath",0).toString();
+ m_pttPortNumber = settings.value("PTTPortNumber",0).toInt();
+ #if !defined(Q_OS_WIN)
+ ptt_set_override(m_pttPath.toUtf8().constData());
+ #endif
m_astroFont=settings.value("AstroFont",20).toInt();
m_xpol=settings.value("Xpol",false).toBool();
ui->actionFind_Delta_Phi->setEnabled(m_xpol);
m_xpolx=settings.value("XpolX",false).toBool();
- m_saveDir=settings.value("SaveDir",m_appDir + "/save").toString();
- m_azelDir=settings.value("AzElDir",m_appDir).toString();
+ m_saveDir=settings.value("SaveDir",QDir {m_dataDir}.absoluteFilePath("save")).toString();
+ m_azelDir=settings.value("AzElDir",m_dataDir).toString();
m_editorCommand=settings.value("Editor","notepad").toString();
m_dxccPfx=settings.value("DXCCpfx","").toString();
m_timeout=settings.value("Timeout",20).toInt();
- txPower=settings.value("TxPower",100).toInt();
- iqAmp=settings.value("IQamp",0).toInt();
- iqPhase=settings.value("IQphase",0).toInt();
m_applyIQcal=settings.value("ApplyIQcal",0).toInt();
ui->actionApply_IQ_Calibration->setChecked(m_applyIQcal!=0);
m_dPhi=settings.value("dPhi",0).toInt();
m_fCal=settings.value("Fcal",0).toInt();
- m_fAdd=settings.value("FAdd",0).toDouble();
+ m_fAdd=settings.value("Fadd",0).toDouble();
soundInThread.setFadd(m_fAdd);
m_network = settings.value("NetworkInput",true).toBool();
m_fs96000 = settings.value("FSam96000",true).toBool();
@@ -533,7 +1063,37 @@ void MainWindow::readSettings()
m_w3szUrl=settings.value("w3szUrl",true).toBool();
m_otherUrl=settings.value("otherUrl","").toString();
m_spot_to_psk_reporter=settings.value("spotPSK",true).toBool();
+ m_psk_reporter_tcpip=settings.value("PSKReporterTCPIP",false).toBool();
+
+ m_tol=settings.value("FTol",500).toInt();
+ m_wide_graph_window->setTol(m_tol);
+ int i = 5;
+ if(m_tol==20) i=1;
+ if(m_tol==50) i=2;
+ if(m_tol==100) i=3;
+ if(m_tol==200) i=4;
+// if(m_tol==500) i=5;
+ if(m_tol==1000) i=6;
+ ui->labTol1->setText(QString::number(m_tol));
+ ui->tolSpinBox->setValue(i);
+
qDebug() << "In mainwindow m_spot_to_psk_reporter is: " << m_spot_to_psk_reporter;
+
+ qDebug() << "In mainwindow m_modeTx is: " << m_modeTx;
+ qDebug() << "In mainwindow m_mode is: " << m_mode;
+ qDebug() << "In mainwindow n_modeJT65 is: " << m_modeJT65;
+ qDebug() << "In mainwindow n_modeQ65 is: " << m_modeQ65;
+ settings.endGroup();
+ }
+
+ {
+ settings.beginGroup("TxTune");
+ g_TxTuneGeometry = settings.value("geometry").toByteArray();
+ txPower=settings.value("TxPower",100).toInt();
+ iqAmp=settings.value("IQamp",0).toInt();
+ iqPhase=settings.value("IQphase",0).toInt();
+ settings.endGroup();
+ }
}
//-------------------------------------------------------------- dataSink()
@@ -545,11 +1105,12 @@ void MainWindow::dataSink(int k)
static int nzap=0;
static int ntrz=0;
static int nkhz;
- static int nfsample=96000;
- static int nxpol=0;
+ int nfsample= m_fs96000 ? 96000 : 95238;
+ setNfsample(nfsample);
+ int nxpol= m_xpol ? 1 : 0;
+ setNxpol(nxpol);
static int nsec0=0;
static int nsum=0;
- static float fgreen;
static int ndiskdat;
static int nb;
static int nadj=0;
@@ -559,14 +1120,16 @@ void MainWindow::dataSink(int k)
static float rejecty;
static float slimit;
static double xsum=0.0;
-
+
if(m_diskData) {
ndiskdat=1;
- datcom_.ndiskdat=1;
+ setNdiskdat(1);
} else {
ndiskdat=0;
- datcom_.ndiskdat=0;
+ setNdiskdat(0);
}
+
+ setIdphi(m_dPhi);
// Get x and y power, polarized spectrum, nkhz, and ihsym
nb=0;
if(m_NB) nb=1;
@@ -574,11 +1137,11 @@ void MainWindow::dataSink(int k)
if(!m_fs96000) nfsample=95238;
nxpol=0;
if(m_xpol) nxpol=1;
- fgreen=m_wide_graph_window->fGreen();
nadj++;
if(m_adjustIQ==0) nadj=0;
+
symspec_(&k, &nxpol, &ndiskdat, &nb, &m_NBslider, &m_dPhi,
- &nfsample, &fgreen, &m_adjustIQ, &m_applyIQcal,
+ &nfsample, &m_adjustIQ, &m_applyIQcal,
&m_gainx, &m_gainy, &m_phasex, &m_phasey, &rejectx, &rejecty,
&px, &py, s, &nkhz, &ihsym, &nzap, &slimit, lstrong);
@@ -627,7 +1190,7 @@ void MainWindow::dataSink(int k)
);
} else {
ui->decodedTextBrowser->append(
- QString {"Amp: %1 Phase: %1"}
+ QString {"Amp: %1 Phase: %2"}
.arg (m_gainx, 6, 'f', 4)
.arg (m_phasex, 6, 'f', 4)
);
@@ -653,13 +1216,13 @@ void MainWindow::dataSink(int k)
// Time according to this computer
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
- int ntr = (ms/1000) % m_TRperiod;
- if((m_diskData && ihsym <= m_waterfallAvg) || (!m_diskData && ntr<ntrz)) {
+ int ntr1 = (ms/1000) % m_TRperiod;
+ if((m_diskData && ihsym <= m_waterfallAvg) || (!m_diskData && ntr1<ntrz)) {
for (int i=0; i<NFFT; i++) {
splot[i] = 1.e30;
}
}
- ntrz=ntr;
+ ntrz=ntr1;
n=0;
}
@@ -667,19 +1230,22 @@ void MainWindow::dataSink(int k)
if(m_RxState==0 and ihsym>=280 and !m_diskData) { //Early decode, t=52 s
m_RxState=1;
- datcom_.newdat=1;
- datcom_.nagain=0;
- datcom_.nhsym=ihsym;
+ setDecoderReady(0);
+ setNewdat(1);
+ setNagain(0);
+ setNhsym(ihsym);
QDateTime t = QDateTime::currentDateTimeUtc();
m_dateTime=t.toString("yyyy-MMM-dd hh:mm");
decode(); //Start the decoder
+ // qDebug() << "decoding at t=52s in dataSink in mainwindow.cpp";
}
if(m_RxState<=1 and ihsym>=302) { //Decode at t=56 s (for Q65 and data from disk)
m_RxState=2;
- datcom_.newdat=1;
- datcom_.nagain=0;
- datcom_.nhsym=ihsym;
+ setDecoderReady(0);
+ setNewdat(1);
+ setNagain(0);
+ setNhsym(ihsym);
QDateTime t = QDateTime::currentDateTimeUtc();
m_dateTime=t.toString("yyyy-MMM-dd hh:mm");
decode(); //Start the decoder
@@ -688,151 +1254,239 @@ void MainWindow::dataSink(int k)
t.time().toString("hhmm");
if(m_xpol) fname += ".tf2";
if(!m_xpol) fname += ".iq";
- *future2 = QtConcurrent::run(savetf2, fname, m_xpol);
+ *future2 = QtConcurrent::run([this](QString fname, bool xpol) {
+ this->savetf2(fname, xpol);
+ }, fname, m_xpol);
+
+ qDebug() << "saving to file " << fname << " in dataSink in mainwindow.cpp";
watcher2->setFuture(*future2);
}
}
-
soundInThread.m_dataSinkBusy=false;
}
+/* Generate gaussian random float with mean=0 and std_dev=1 */
+float gran()
+{
+ float fac,rsq,v1,v2;
+ static float gset;
+ static int iset;
+
+ if(iset){
+ /* Already got one */
+ iset = 0;
+ return gset;
+ }
+ /* Generate two evenly distributed numbers between -1 and +1
+ * that are inside the unit circle
+ */
+ do {
+ v1 = 2.0 * (float)rand() / RAND_MAX - 1;
+ v2 = 2.0 * (float)rand() / RAND_MAX - 1;
+ rsq = v1*v1 + v2*v2;
+ } while(rsq >= 1.0 || rsq == 0.0);
+ fac = sqrt(-2.0*log(rsq)/rsq);
+ gset = v1*fac;
+ iset++;
+ return v2*fac;
+}
+
+float* MainWindow::getDd() const
+{
+ return dd;
+}
+
+void MainWindow::savetf2(QString fname, bool xpol)
+{
+ int npts=2*56*96000;
+ if(xpol) npts=2*npts;
+ FILE* fp = fopen(fname.toUtf8().constData(), "wb");
+
+ if (!fp) {
+ qDebug() << "FAILED TO OPEN FILE:" << fname;
+ perror("fopen");
+ return;
+ }
+
+ qint16* buf = static_cast<qint16*>(malloc(npts * sizeof(*buf)));
+
+ if(fp != NULL) {
+ double fcenter = getFcenter();
+ //fcenter = 1296.125;
+ fwrite(&fcenter, sizeof(fcenter), 1, fp); // Write fcenter to file
+ uint64_t zero = 0;
+ fwrite(&zero, sizeof(zero), 1, fp); // another 8 bytes
+ qDebug() << "in savetf2 fcenter is: " << fcenter;
+
+ int j = 0;
+ for (int i = 0; i < npts; i += 2) {
+ buf[i] = static_cast<qint16>(dd[j++]);
+ buf[i + 1] = static_cast<qint16>(dd[j++]);
+ if (!xpol) j += 2; // Skip over dd(3,x) and dd(4,x)
+ }
+
+ fwrite(buf, sizeof(buf[0]), npts, fp);
+ qDebug() << "saving file " << fname << " to disk in savetf2 in mainwindow.cpp";
+ fclose(fp);
+ }
+ free(buf);
+}
+
+void MainWindow::getfile(QString fname, bool xpol, int dbDgrd)
+{
+ setDecoderReady(0);
+ int npts = 2 * 56 * 96000;
+ if (xpol) npts = 2 * npts;
+
+ // j indexes dd[], which has 4 channels per pair
+ int j = 0;
+
+ // Clear id[] properly
+ memset(id, 0, npts * sizeof(id[0]));
+
+ // Open file
+ FILE* fp = fopen(fname.toUtf8().constData(), "rb");
+ if (!fp) {
+ qWarning() << "Failed to open file:" << fname;
+ return;
+ }
+
+ // Read fcenter
+ double fcenter = 0.0;
+ if (fread(&fcenter, sizeof(fcenter), 1, fp) != 1) {
+ fclose(fp);
+ return;
+ }
+
+ setFcenter(fcenter);
+
+ // Skip the 8-byte zero padding
+ uint64_t pad = 0;
+ if (fread(&pad, sizeof(pad), 1, fp) != 1) {
+ fclose(fp);
+ return;
+ }
+
+
+ // Read raw samples
+ size_t nRead = fread(id, sizeof(id[0]), npts, fp);
+ qDebug() << "fread read" << nRead << "samples, expected" << npts;
+
+ fclose(fp);
+
+ // Compute degradation factors
+ float dgrd = 0.0;
+ if (dbDgrd < 0)
+ dgrd = 23.0 * sqrt(pow(10.0, -0.1 * (double)dbDgrd) - 1.0);
+
+ float fac = 23.0 / sqrt(dgrd * dgrd + 23.0 * 23.0);
+
+ // Fill dd[]
+ j = 0;
+ for (int i = 0; i < npts; i += 2) {
+
+ if (dbDgrd < 0) {
+ dd[j++] = fac * ((float)id[i] + dgrd * gran());
+ dd[j++] = fac * ((float)id[i + 1] + dgrd * gran());
+ } else {
+ dd[j++] = id[i];
+ dd[j++] = id[i + 1];
+ }
+
+ if (!xpol) {
+ // Skip channels 3 and 4
+ j += 2;
+
+ }
+ }
+
+ // qDebug() << "GETFILE: starting decode for:" << fname;
+ setNdiskdat(1);
+ int nfreq = getFcenter();
+ if (nfreq > 9998) setFcenter(9990.100);
+
+ int i0 = fname.indexOf(".tf2");
+ if (i0 < 0) i0 = fname.indexOf(".iq");
+
+ setNutc(0);
+ if (i0 > 0) {
+ setNutc(100 * fname.mid(i0 - 4, 2).toInt() +
+ fname.mid(i0 - 2, 2).toInt());
+ }
+}
+
void MainWindow::showSoundInError(const QString& errorMsg)
{QMessageBox::critical(this, tr("Error in SoundIn"), errorMsg);}
void MainWindow::showStatusMessage(const QString& statusMsg)
{statusBar()->showMessage(statusMsg);}
-void MainWindow::on_actionDeviceSetup_triggered() //Setup Dialog
+void MainWindow::on_actionDeviceSetup_triggered()
{
DevSetup dlg(this);
- dlg.m_myCall=m_myCall;
- dlg.m_myGrid=m_myGrid;
- dlg.m_idInt=m_idInt;
- dlg.m_pttPort=m_pttPort;
- dlg.m_astroFont=m_astroFont;
- dlg.m_xpol=m_xpol;
- dlg.m_xpolx=m_xpolx;
- dlg.m_saveDir=m_saveDir;
- dlg.m_azelDir=m_azelDir;
- dlg.m_editorCommand=m_editorCommand;
- dlg.m_dxccPfx=m_dxccPfx;
- dlg.m_timeout=m_timeout;
- dlg.m_dPhi=m_dPhi;
- dlg.m_fCal=m_fCal;
- dlg.m_fAdd=m_fAdd;
- dlg.m_network=m_network;
- dlg.m_fs96000=m_fs96000;
- dlg.m_nDevIn=m_nDevIn;
- dlg.m_nDevOut=m_nDevOut;
- dlg.m_udpPort=m_udpPort;
- dlg.m_IQswap=m_IQswap;
- dlg.m_dB=m_dB;
- dlg.m_initIQplus=m_initIQplus;
- dlg.m_bIQxt=m_bIQxt;
- dlg.m_cal570=m_cal570;
- dlg.m_TxOffset=m_TxOffset;
- dlg.m_mult570=m_mult570;
- dlg.m_mult570Tx=m_mult570Tx;
- dlg.m_colors=m_colors;
- dlg.m_w3szUrl = m_w3szUrl; //liveCQ
- dlg.m_otherUrl=m_otherUrl; //liveCQ
- dlg.m_spot_to_psk_reporter = m_spot_to_psk_reporter;
-
dlg.initDlg();
- if(dlg.exec() == QDialog::Accepted) {
- m_myCall=dlg.m_myCall;
- m_myGrid=dlg.m_myGrid;
- m_idInt=dlg.m_idInt;
- m_pttPort=dlg.m_pttPort;
- m_astroFont=dlg.m_astroFont;
- if(m_astro_window && m_astro_window->isVisible()) m_astro_window->setFontSize(m_astroFont);
- m_xpol=dlg.m_xpol;
- ui->actionFind_Delta_Phi->setEnabled(m_xpol);
- m_xpolx=dlg.m_xpolx;
- m_saveDir=dlg.m_saveDir;
- m_azelDir=dlg.m_azelDir;
- m_editorCommand=dlg.m_editorCommand;
- m_dxccPfx=dlg.m_dxccPfx;
- m_timeout=dlg.m_timeout;
- m_dPhi=dlg.m_dPhi;
- m_fCal=dlg.m_fCal;
- m_fAdd=dlg.m_fAdd;
- m_wide_graph_window->setFcal(m_fCal);
- m_fs96000=dlg.m_fs96000;
- m_network=dlg.m_network;
- m_nDevIn=dlg.m_nDevIn;
- m_paInDevice=dlg.m_paInDevice;
- m_nDevOut=dlg.m_nDevOut;
- m_paOutDevice=dlg.m_paOutDevice;
- m_udpPort=dlg.m_udpPort;
- m_IQswap=dlg.m_IQswap;
- m_dB=dlg.m_dB;
- m_initIQplus=dlg.m_initIQplus;
- m_bIQxt=dlg.m_bIQxt;
- m_colors=dlg.m_colors;
- m_messages_window->setColors(m_colors);
- m_band_map_window->setColors(m_colors);
- m_cal570=dlg.m_cal570;
- m_TxOffset=dlg.m_TxOffset;
- m_mult570Tx=dlg.m_mult570Tx;
- m_wide_graph_window->m_mult570=m_mult570;
- m_wide_graph_window->m_mult570Tx=m_mult570Tx;
- m_wide_graph_window->m_cal570=m_cal570;
- soundInThread.setSwapIQ(m_IQswap);
- soundInThread.setScale(m_dB);
- m_w3szUrl=dlg.m_w3szUrl;
- m_otherUrl=dlg.m_otherUrl;
- m_spot_to_psk_reporter=dlg.m_spot_to_psk_reporter;
- QSettings settings(m_settings_filename, QSettings::IniFormat);
+
+ if (dlg.exec() == QDialog::Accepted)
{
- SettingsGroup g {&settings, "MainWindow"};
- }
- SettingsGroup g {&settings, "Common"};
- settings.setValue("w3szUrl",m_w3szUrl); //liveCQ
- settings.setValue("otherUrl",m_otherUrl); //liveCQ
- settings.setValue("spotPSK",m_spot_to_psk_reporter);
- settings.setValue("MyCall",m_myCall);
- settings.setValue("MyGrid",m_myGrid);
- settings.setValue("IDint",m_idInt);
- settings.setValue("PTTport",m_pttPort);
- settings.setValue("AstroFont",m_astroFont);
- settings.setValue("Xpol",m_xpol);
- settings.setValue("XpolX",m_xpolx);
- settings.setValue("SaveDir",m_saveDir);
- settings.setValue("AzElDir",m_azelDir);
- settings.setValue("Editor",m_editorCommand);
- settings.setValue("DXCCpfx",m_dxccPfx);
- settings.setValue("Timeout",m_timeout);
- settings.setValue("TxPower",txPower);
- settings.setValue("IQamp",iqAmp);
- settings.setValue("IQphase",iqPhase);
- settings.setValue("ApplyIQcal",m_applyIQcal);
- settings.setValue("dPhi",m_dPhi);
- settings.setValue("Fcal",m_fCal);
- settings.setValue("Fadd",m_fAdd);
-
- if(dlg.m_restartSoundIn) {
+ //
+ // Apply runtime effects for SoundIn
+ //
+ if (dlg.m_restartSoundIn)
+ {
soundInThread.quit();
soundInThread.wait(1000);
+
+ soundInThread.setInputDevice(m_paInDevice);
soundInThread.setNetwork(m_network);
- if(m_fs96000) soundInThread.setRate(96000.0);
- if(!m_fs96000) soundInThread.setRate(95238.1);
soundInThread.setFadd(m_fAdd);
- if(!m_xpol) soundInThread.setNrx(1);
- if(m_xpol) soundInThread.setNrx(2);
- soundInThread.setInputDevice(m_paInDevice);
+ soundInThread.setRate(m_fs96000 ? 96000.0 : 95238.1);
+ soundInThread.setSwapIQ(m_IQswap);
+ soundInThread.setScale(m_dB);
+ soundInThread.setPort(m_udpPort);
+ soundInThread.setNrx(m_xpol ? 2 : 1);
+
soundInThread.start(QThread::HighestPriority);
}
- if(dlg.m_restartSoundOut) {
+ //
+ // Apply runtime effects for SoundOut
+ //
+ if (dlg.m_restartSoundOut)
+ {
soundOutThread.quitExecution=true;
soundOutThread.wait(1000);
+
soundOutThread.setOutputDevice(m_paOutDevice);
-// soundOutThread.start(QThread::HighPriority);
+ soundOutThread.start();
}
+
+ //
+ // GUI updates
+ //
+ if (m_astro_window && m_astro_window->isVisible())
+ m_astro_window->setFontSize(m_astroFont);
+
+ ui->actionFind_Delta_Phi->setEnabled(m_xpol);
+
+ m_messages_window->setColors(m_colors);
+ m_band_map_window->setColors(m_colors);
+
+ //
+ // WideGraph updates
+ //
+ m_wide_graph_window->m_mult570 = m_mult570;
+ m_wide_graph_window->m_mult570Tx = m_mult570Tx;
+ m_wide_graph_window->m_cal570 = m_cal570;
+ m_wide_graph_window->setFcal(m_fCal);
+
+ //
+ // Save to disk
+ //
+ writeSettings();
}
}
+
void MainWindow::on_monitorButton_clicked() //Monitor
{
m_monitoring=true;
@@ -1023,39 +1677,39 @@ void MainWindow::on_actionExit_triggered() //Exit()
close ();
}
-void MainWindow::closeEvent (QCloseEvent * e)
+void MainWindow::closeEvent(QCloseEvent *e)
{
- if (m_gui_timer) m_gui_timer->stop ();
- m_wide_graph_window->saveSettings();
- QFile quitFile(m_appDir + "/.quit");
- quitFile.open(QIODevice::ReadWrite);
- QFile lockFile(m_appDir + "/.lock");
- lockFile.remove(); // Allow m65 to terminate
+ set_stop_m65(1);
+ if (m_gui_timer) m_gui_timer->stop();
+ m_wide_graph_window->saveSettings();
- // close pipes
- proc_m65.closeReadChannel (QProcess::StandardOutput);
- proc_m65.closeReadChannel (QProcess::StandardError);
+ QFile quitFile(QDir {m_dataDir}.absoluteFilePath (".quit"));
+ (void)quitFile.open(QFileDevice::ReadWrite);
+ setQuitID(quitFile.handle());
- // flush all input
- proc_m65.setReadChannel (QProcess::StandardOutput);
- proc_m65.readAll ();
- proc_m65.setReadChannel (QProcess::StandardError);
- proc_m65.readAll ();
+ if (m_astro_window) m_astro_window->close();
+ if (m_band_map_window) m_band_map_window->close();
+ if (m_messages_window) {
+ m_messages_window->setClosingForShutdown(true);
+ m_messages_window->close();
+ }
+ if (m_wide_graph_window) m_wide_graph_window->close();
- proc_m65.disconnect ();
- if (!proc_m65.waitForFinished (1000)) proc_m65.kill();
- quitFile.remove();
- mem_m65.detach();
- if (m_astro_window) m_astro_window->close ();
- if (m_band_map_window) m_band_map_window->close ();
- if (m_messages_window) {
- m_messages_window->setClosingForShutdown(true);
- m_messages_window->close(); // Now closeEvent runs fully
- }
- if (m_wide_graph_window) m_wide_graph_window->close ();
- QMainWindow::closeEvent (e);
+#ifdef __unix__
+ ptt_close(); // close persistent Linux serial port
+#endif
+
+ if (g_pTxTune) {
+ g_pTxTune->close();
+ delete g_pTxTune;
+ g_pTxTune = nullptr;
+ }
+
+ quitFile.remove();
+ QMainWindow::closeEvent(e);
}
+
void MainWindow::on_stopButton_clicked() //stopButton
{
m_monitoring=false;
@@ -1127,6 +1781,9 @@ void MainWindow::on_actionOpen_triggered() //Open File
{
m_monitoring=false;
soundInThread.setMonitoring(m_monitoring);
+ // Wipe waterfall callsign overlay so stale labels from the previous
+ // file (or live capture) don't linger over the new decode.
+ if (m_wide_graph_window) m_wide_graph_window->clearDecodeLabels();
QString fname;
if(m_xpol) {
fname=QFileDialog::getOpenFileName(this, "Open File", m_path,
@@ -1146,15 +1803,26 @@ void MainWindow::on_actionOpen_triggered() //Open File
}
on_stopButton_clicked();
m_diskData=true;
+ m_decoderBusy=true; //added 1.6.25 w3sz
int dbDgrd=0;
if(m_myCall=="K1JT" and m_idInt<0) dbDgrd=m_idInt;
- *future1 = QtConcurrent::run(getfile, fname, m_xpol, dbDgrd);
+ *future1 = QtConcurrent::run([this](QString fname, bool xpol, int dbDgrd) {
+ this->getfile(fname, xpol, dbDgrd);
+ }, fname, m_xpol, dbDgrd);
+ // qDebug() << QDateTime::currentMSecsSinceEpoch() << "MainWindow::on_actionOpen_triggered Reading wav file: " << m_path;
watcher1->setFuture(*future1);
}
}
void MainWindow::on_actionOpen_next_in_directory_triggered() //Open Next
{
+ if (m_decoderBusy) {
+ qDebug() << "Decode is busy; not starting next file yet.";
+ return;
+ }
+ m_decoderBusy = true;
+ if (m_wide_graph_window) m_wide_graph_window->clearDecodeLabels();
+
int i,len;
QFileInfo fi(m_path);
QStringList list;
@@ -1165,22 +1833,25 @@ void MainWindow::on_actionOpen_next_in_directory_triggered() //Open Next
}
for (i = 0; i < list.size()-1; ++i) {
if(i==list.size()-2) m_loopall=false;
- len=list.at(i).length();
- if(list.at(i)==m_path.right(len)) {
+ const QString &entry = list.at(i);
+ len = entry.length();
+ if (entry == m_path.right(len)) {
int n=m_path.length();
- QString fname=m_path.replace(n-len,len,list.at(i+1));
+ QString fname = m_path;
+ fname.replace(n - len, len, list.at(i+1));
m_path=fname;
- int i;
- i=fname.indexOf(".iq") - 11;
- if(m_xpol) i=fname.indexOf(".tf2") - 11;
- if(i>=0) {
+ int idx = fname.indexOf(m_xpol ? ".tf2" : ".iq") - 11;
+ if (idx >= 0) {
lab1->setStyleSheet("QLabel{background-color: #66ff66}");
- lab1->setText(" " + fname.mid(i,len) + " ");
+ lab1->setText(" " + fname.mid(idx, len) + " ");
}
m_diskData=true;
int dbDgrd=0;
if(m_myCall=="K1JT" and m_idInt<0) dbDgrd=m_idInt;
- *future1 = QtConcurrent::run(getfile, fname, m_xpol, dbDgrd);
+ *future1 = QtConcurrent::run([this](QString fname, bool xpol, int dbDgrd) {
+ this->getfile(fname, xpol, dbDgrd);
+ }, fname, m_xpol, dbDgrd);
+ // qDebug() << "MainWindow::on_actionOpen_next_in_directory_triggered Reading wav file: " << m_path;
watcher1->setFuture(*future1);
return;
}
@@ -1198,9 +1869,9 @@ void MainWindow::diskDat() //diskDat()
double hsym;
//These may be redundant??
m_diskData=true;
- datcom_.newdat=1;
+ setNewdat(1);
if(m_wide_graph_window->m_bForceCenterFreq) {
- datcom_.fcenter=m_wide_graph_window->m_dForceCenterFreq;
+ setFcenter(m_wide_graph_window->m_dForceCenterFreq);
}
if(m_fs96000) hsym=2048.0*96000.0/11025.0; //Samples per JT65 half-symbol
@@ -1215,6 +1886,7 @@ void MainWindow::diskDat() //diskDat()
void MainWindow::diskWriteFinished() //diskWriteFinished
{
// qDebug() << "diskWriteFinished";
+// decode();
}
//Delete ../save/*.tf2
void MainWindow::on_actionDelete_all_tf2_files_in_SaveDir_triggered()
@@ -1314,8 +1986,8 @@ void MainWindow::on_DecodeButton_clicked() //Decode request
int n=m_sec0%m_TRperiod;
if(m_monitoring and n>47 and (n<52 or m_decoderBusy)) return;
if(!m_decoderBusy) {
- datcom_.newdat=0;
- datcom_.nagain=1;
+ setNewdat(0);
+ setNagain(1);
decode();
}
}
@@ -1324,123 +1996,126 @@ void MainWindow::freezeDecode(int n) //freezeDecode()
{
if(n==2) {
ui->tolSpinBox->setValue(5);
- datcom_.ntol=m_tol;
- datcom_.mousedf=0;
+ setNtol(m_tol);
+ setMousedf(0);
} else {
ui->tolSpinBox->setValue(qMin(3,ui->tolSpinBox->value()));
- datcom_.ntol=m_tol;
+ setNtol(m_tol);
}
if(!m_decoderBusy) {
- datcom_.nagain=1;
- datcom_.newdat=0;
+ setNagain(1);
+ setNewdat(0);
decode();
}
}
void MainWindow::decode() //decode()
{
+ decodeBusy(true);
+ // Reset decode-finished count for this file
+ m_decodeFinishedCount = 0;
+
ui->DecodeButton->setStyleSheet(m_pbdecoding_style1);
// QFile f("mockRTfiles.txt");
// if(datcom_.nagain==0 && (!m_diskData) && !f.exists()) {
- if(datcom_.nagain==0 && (!m_diskData)) {
+ if(getNagain()==0 && (!m_diskData)) {
qint64 ms = QDateTime::currentMSecsSinceEpoch() % 86400000;
int imin=ms/60000;
int ihr=imin/60;
imin=imin % 60;
- datcom_.nutc=100*ihr + imin;
+ setNutc(100*ihr + imin);
}
- datcom_.idphi=m_dPhi;
- datcom_.mousedf=m_wide_graph_window->DF();
- datcom_.mousefqso=m_wide_graph_window->QSOfreq();
- datcom_.ndepth=m_ndepth;
- datcom_.ndiskdat=0;
+ setIdphi(m_dPhi);
+ setMousedf(m_wide_graph_window->DF());
+ setMousefqso(m_wide_graph_window->QSOfreq());
+ setNdepth(m_ndepth);
+ setNdiskdat(0);
if(m_diskData) {
- datcom_.ndiskdat=1;
- int i0=m_path.indexOf(".tf2");
- if(i0<0) i0=m_path.indexOf(".iq");
- if(i0>0) {
- // Compute self Doppler using the filename for Date and Time
- int nyear=m_path.mid(i0-11,2).toInt()+2000;
- int month=m_path.mid(i0-9,2).toInt();
- int nday=m_path.mid(i0-7,2).toInt();
- int nhr=m_path.mid(i0-4,2).toInt();
- int nmin=m_path.mid(i0-2,2).toInt();
- double uth=nhr + nmin/60.0;
- int nfreq=(int)datcom_.fcenter;
- int ndop00;
-
- astrosub00_(&nyear, &month, &nday, &uth, &nfreq, m_myGrid.toLatin1(),&ndop00,6);
- datcom_.nfast=ndop00; //Send self Doppler to decoder, via datcom
+ if(m_myGrid.trimmed().length()>=6) {
+ setNdiskdat(1);
+ setNagain(0);
+ int i0=m_path.indexOf(".tf2");
+ if(i0<0) i0=m_path.indexOf(".iq");
+ if(i0>0) {
+ // Compute self Doppler using the filename for Date and Time
+ int nyear=m_path.mid(i0-11,2).toInt()+2000;
+ int month=m_path.mid(i0-9,2).toInt();
+ int nday=m_path.mid(i0-7,2).toInt();
+ int nhr=m_path.mid(i0-4,2).toInt();
+ int nmin=m_path.mid(i0-2,2).toInt();
+ double uth=nhr + nmin/60.0;
+ int nfreq = getFcenter();
+ int ndop00;
+ QByteArray myGridData = m_myGrid.toLatin1();
+ astrosub00_(&nyear, &month, &nday, &uth, &nfreq, myGridData.constData(),&ndop00, myGridData.size());
+ setNdop00(ndop00); //Send self Doppler to decoder, via datcom
+ }
+ }
+ else {
+ QMessageBox::information(this,"MAP65","No 6-digit MyGrid recognized by decode()");
+ return;
}
}
- datcom_.neme=0;
- if(ui->actionOnly_EME_calls->isChecked()) datcom_.neme=1;
+ setNeme(0);
+ if(ui->actionOnly_EME_calls->isChecked()) setNeme(1);
+
+ int ispan = int(m_wide_graph_window->fSpan());
+ if (ispan % 2 == 1) ispan++;
+
+ double fc = getFcenter(); //MHz
+ // ifc is fractional kHz of RF center, used to align baseband window with RF dial.
+ // Must stay in [0, 999]. Changing fcenter semantics will break wideband.
+ int ifc = int(1000.0*(fc - int(fc)) + 0.5); // fractional kHz of RF center
- int ispan=int(m_wide_graph_window->fSpan());
- if(ispan%2 == 1) ispan++;
- int ifc=int(1000.0*(datcom_.fcenter - int(datcom_.fcenter))+0.5);
int nfa=m_wide_graph_window->nStartFreq();
int nfb=nfa+ispan;
int nfshift=nfa + ispan/2 - ifc;
- datcom_.nfa=nfa;
- datcom_.nfb=nfb;
- datcom_.nfcal=m_fCal;
- datcom_.nfshift=nfshift;
- datcom_.mcall3=0;
- if(m_call3Modified) datcom_.mcall3=1;
- datcom_.ntimeout=m_timeout;
- datcom_.ntol=m_tol;
- datcom_.nxant=0;
- if(m_xpolx) datcom_.nxant=1;
- if(datcom_.nutc < m_nutc0) m_map65RxLog |= 1; //Date and Time to map65_rx.log
- m_nutc0=datcom_.nutc;
- datcom_.map65RxLog=m_map65RxLog;
- datcom_.nfsample=96000;
- if(!m_fs96000) datcom_.nfsample=95238;
- datcom_.nxpol=0;
- if(m_xpol) datcom_.nxpol=1;
- datcom_.nmode=10*m_modeQ65 + m_modeJT65;
+ setNfa(nfa);
+ setNfb(nfb);
+ setNfshift(nfshift);
+
+ setNfcal(m_fCal);
+ setMcall3(0);
+ if(m_call3Modified) setMcall3(1);
+ setNtimeout(m_timeout);
+ setNtol(m_tol);
+ setNxant(0);
+ if(m_xpolx) setNxant(1);
+ if(getNutc() < m_nutc0) m_map65RxLog |= 1; //Date and Time to map65_rx.log
+ m_nutc0=getNutc();
+ setMap65RxLog(m_map65RxLog);
+ setNfsample(96000);
+ if(!m_fs96000) setNfsample(95238);
+ setNxpol(0);
+ if(m_xpol) setNxpol(1);
+ setNmode(10*m_modeQ65 + m_modeJT65);
// datcom_.nfast=1; //No longer used
- datcom_.nsave=m_nsave;
- datcom_.max_drift=ui->sbMaxDrift->value();
-
- QString mcall=(m_myCall+" ").mid(0,12);
- QString mgrid=(m_myGrid+" ").mid(0,6);
- QString hcall=(ui->dxCallEntry->text()+" ").mid(0,12);
- QString hgrid=(ui->dxGridEntry->text()+" ").mid(0,6);
-
- memcpy(datcom_.mycall, mcall.toLatin1(), 12);
- memcpy(datcom_.mygrid, mgrid.toLatin1(), 6);
- memcpy(datcom_.hiscall, hcall.toLatin1(), 12);
- memcpy(datcom_.hisgrid, hgrid.toLatin1(), 6);
- memcpy(datcom_.datetime, m_dateTime.toLatin1(), 17);
- datcom_.junk1=1234;
- datcom_.junk2=5678;
-
- //newdat=1 ==> this is new data, must do the big FFT
- //nagain=1 ==> decode only at fQSO +/- Tol
-
- char *to = (char*)mem_m65.data();
- char *from = (char*) datcom_.d4;
- int size=sizeof(datcom_);
- if(datcom_.newdat==0) {
- int noffset = 4*4*5760000 + 4*4*322*32768 + 4*4*32768;
- to += noffset;
- from += noffset;
- size -= noffset;
- }
- memcpy(to, from, qMin(mem_m65.size(), size-8));
- datcom_.nagain=0;
- datcom_.ndiskdat=0;
+ setNsave(m_nsave);
+ setMaxDrift(ui->sbMaxDrift->value());
+
+QString mcall = (m_myCall + " ").mid(0, 12);
+QString mgrid = (m_myGrid + " ").mid(0, 6);
+QString hcall = (ui->dxCallEntry->text() + " ").mid(0, 12);
+QString hgrid = (ui->dxGridEntry->text() + " ").mid(0, 6);
+
+ setMyCall(mcall);
+ setMyGrid(mgrid);
+ setHisCall(hcall);
+ setHisGrid(hgrid);
+ setDatetime(m_dateTime);
+ setNewdat(1);
+ setJunk1(1234);
+ setJunk2(5678);
+
+ setNagain(0); //added 12-30-25 to agree with legacy
+ if (!m_diskData) setNdiskdat(0); //added 12-30-25 to agree with legacy
+ setDecoderReady(1);
m_map65RxLog=0;
m_call3Modified=false;
-
- QFile lockFile(m_appDir + "/.lock"); // Allow m65 to start
- lockFile.remove();
- decodeBusy(true);
+// qDebug() << QDateTime::currentMSecsSinceEpoch() << "finished MainWindow::decode()";
}
bool MainWindow::subProcessFailed (QProcess * process, int exit_code, QProcess::ExitStatus status)
@@ -1453,6 +2128,7 @@ bool MainWindow::subProcessFailed (QProcess * process, int exit_code, QProcess::
if (argument.contains (' ')) argument = '"' + argument + '"';
arguments << argument;
}
+ writeCrashData();
MessageBox::critical_message (this, tr ("Subprocess Error")
, tr ("Subprocess failed with exit code %1")
.arg (exit_code)
@@ -1464,89 +2140,54 @@ bool MainWindow::subProcessFailed (QProcess * process, int exit_code, QProcess::
return false;
}
-void MainWindow::m65_error (QProcess::ProcessError)
-{
- msgBox("Error starting or running\n" + m_appDir + "/m65 -s\n\n"
- + proc_m65.errorString ());
- QTimer::singleShot (0, this, SLOT (close ()));
-}
+void MainWindow::writeCrashData() {
+ QFile file("crash_data.txt");
-void MainWindow::editor_error() //editor_error
-{
- msgBox("Error starting or running\n" + m_appDir + "/" + m_editorCommand);
-}
+ if (file.open(QIODevice::Append | QIODevice::Text)) {
+ QTextStream out(&file);
-void MainWindow::readFromStdout() //readFromStdout
-{
- while(proc_m65.canReadLine())
- {
- QByteArray t=proc_m65.readLine();
- if(t.indexOf("<QuickDecodeDone>") >= 0) {
- m_nsum=t.mid(17,4).toInt();
- m_nsave=t.mid(21,4).toInt();
- lab7->setText (QString {"Avg: %1"}.arg (m_nsum));
- if(m_modeQ65>0) m_wide_graph_window->setDecodeFinished();
- }
+ out << "---- Crash Data Dump ----\n";
- if((t.indexOf("<EarlyFinished>") >= 0) or (t.indexOf("<DecodeFinished>") >= 0)) {
- if(m_widebandDecode) {
- m_messages_window->setText(m_messagesText,m_bandmapText);
- m_band_map_window->setText(m_bandmapText);
- m_widebandDecode=false;
- }
- QFile lockFile(m_appDir + "/.lock");
- lockFile.open(QIODevice::ReadWrite);
- if(t.indexOf("<DecodeFinished>") >= 0) {
- int ndecodes=t.mid(40,5).toInt();
- lab5->setText(QString::number(ndecodes));
- m_map65RxLog=0;
- m_startAnother=m_loopall;
- }
- ui->DecodeButton->setStyleSheet("");
- decodeBusy(false);
- return;
- }
+ out << "fcenter: " << getFcenter() << "\n";
- read_log();
+ out << "nutc: " << getNutc() << ", idphi: " << getIdphi()
+ << ", mousedf: " << getMousedf() << ", mousefqso: " << getMousefqso()
+ << ", nagain: " << getNagain() << ", ndepth: " << getNdepth() << "\n";
- if(t.indexOf("!") >= 0) {
- int n=t.length();
- int m=2;
-#ifdef WIN32
- m=3;
-#endif
- if(n>=30 or t.indexOf("Best-fit")>=0) ui->decodedTextBrowser->append(t.mid(1,n-m));
- n=ui->decodedTextBrowser->verticalScrollBar()->maximum();
- ui->decodedTextBrowser->verticalScrollBar()->setValue(n);
- m_messagesText="";
- m_bandmapText="";
- }
+ out << "ndiskdat: " << getNdiskdat() << ", neme: " << getNeme()
+ << ", newdat: " << getNewdat() << ", nfa: " << getNfa()
+ << ", nfb: " << getNfb() << ", nfcal: " << getNfcal()
+ << ", nfshift: " << getNfshift() << "\n";
- if(t.indexOf("@") >= 0) {
- m_messagesText += t.mid(1);
- m_widebandDecode=true;
- }
+ out << "mcall3: " << getMcall3() << ", ntimeout: " << getNtimeout()
+ << ", ntol: " << getNtol() << ", nxant: " << getNxant()
+ << ", map65RxLog: " << getMap65RxLog() << ", nfsample: " << getNfsample() << "\n";
- if(t.indexOf("&") >= 0) {
- QString q(t);
- QString callsign=q.mid(5);
- callsign=callsign.mid(0,callsign.indexOf(" "));
- if(callsign.length()>2) {
- if(m_worked[callsign]) {
- q=q.mid(1,4) + " " + q.mid(5);
- } else {
- q=q.mid(1,4) + " *" + q.mid(5);
- }
- m_bandmapText += q;
- }
- }
- if(t.indexOf("=") >= 0) {
- int n=t.size();
- qDebug() << t.mid(1,n-3).trimmed();
- }
+ out << "nxpol: " << getNxpol() << ", nmode: " << getNmode()
+ << ", nsave: " << getNsave()
+ << ", max_drift: " << getMaxDrift() << ", nhsym: " << getNhsym() << "\n";
+
+ out << "junk1: " << getJunk1() << ", junk2: " << getJunk2() << "\n";
+
+ out << "mycall: " << getMyCall() << "\n";
+ out << "hiscall: " << getHisCall() << "\n";
+ out << "mygrid: " << getMyGrid() << "\n";
+ out << "hisgrid: " << getHisGrid() << "\n";
+ out << "datetime: " << getDatetime() << "\n";
+
+ out << "--------------------------\n";
+
+ file.close();
+ } else {
+ qWarning("Could not open crash_data.txt for writing.");
}
}
+void MainWindow::editor_error() //editor_error
+{
+ msgBox("Error starting or running\n" + m_appDir + "/" + m_editorCommand);
+}
+
void MainWindow::on_EraseButton_clicked()
{
qint64 ms=QDateTime::currentMSecsSinceEpoch();
@@ -1560,6 +2201,7 @@ void MainWindow::on_EraseButton_clicked()
void MainWindow::decodeBusy(bool b) //decodeBusy()
{
+// qDebug() << QDateTime::currentMSecsSinceEpoch() << "decodeBusy(" << b << ")";
m_decoderBusy=b;
ui->DecodeButton->setEnabled(!b);
ui->actionOpen->setEnabled(!b);
@@ -1604,26 +2246,35 @@ void MainWindow::guiUpdate()
bTune0=bTune;
if(m_auto or bTune) {
- if((bTxTime or bTune) and iptt==0 and !m_txMute) {
- int itx=1;
- int ierr = ptt_(&m_pttPort,&itx,&iptt); // Raise PTT
- if(ierr != 0) {
- on_stopTxButton_clicked();
- char s[18];
- sprintf(s,"Cannot open COM%d",m_pttPort);
- msgBox(s);
+ if ((bTxTime or bTune) && iptt == 0 && !m_txMute) {
+
+ if (m_pttPath != "NONE") {
+ int itx = 1;
+ int nport = m_pttPortNumber; // the real COM port number
+ int ierr = ptt_(&nport, &itx, &iptt);
+
+ if (ierr != 0) {
+ if (!m_pttErrorShown) {
+ char s[256];
+ snprintf(s, sizeof(s), "Cannot open Port: %s",
+ m_pttPath.toUtf8().constData());
+ msgBox(s);
+ m_pttErrorShown = true;
+ }
+ on_stopTxButton_clicked();
}
+ }
- if(m_bIQxt) m_wide_graph_window->tx570(); // Set Si570 to Tx Freq
+ if (m_bIQxt)
+ m_wide_graph_window->tx570();
- if(!soundOutThread.isRunning()) {
+ if (!soundOutThread.isRunning())
soundOutThread.start(QThread::HighPriority);
}
- }
- if((!bTxTime and !bTune) or m_txMute) {
+
+ if ((!bTxTime && !bTune) || m_txMute)
btxok=false;
}
- }
// Calculate Tx waveform when needed
if((iptt==1 && iptt0==0) || m_restart) {
@@ -1641,7 +2292,7 @@ void MainWindow::guiUpdate()
int mode65=m_mode65;
int ntxFreq=1000;
double samfac=1.0;
-
+ qDebug() << mode65 << samfac;
if(m_modeTx=="JT65") {
gen65_(message,&mode65,&samfac,&nsendingsh,msgsent,iwave,
&nwave,len1,len1);
@@ -1656,7 +2307,7 @@ void MainWindow::guiUpdate()
QString t=" Tx " + m_modeTx + " ";
t=t.left(11);
QFile f("map65_tx.log");
- f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
+ qDebug() << "MainWindow::guiUpdate 1 File open result:" << f.open(QFileDevice::WriteOnly | QFileDevice::Text | QFileDevice::Append);
QTextStream out(&f);
out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm")
<< t << QString::fromLatin1(msgsent)
@@ -1687,7 +2338,7 @@ void MainWindow::guiUpdate()
QString t=" Tx " + m_modeTx + " ";
t=t.left(11);
QFile f("map65_tx.log");
- f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
+ qDebug() << "MainWindow::guiUpdate 2 File open result:" << f.open(QFileDevice::WriteOnly | QFileDevice::Text | QFileDevice::Append);
QTextStream out(&f);
out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm")
<< t << QString::fromLatin1(msgsent)
@@ -1706,8 +2357,11 @@ void MainWindow::guiUpdate()
if(nc0 <= 0) nc0++;
if(nc0 == 0) {
if(m_bIQxt) m_wide_graph_window->rx570(); // Set Si570 back to Rx Freq
- int itx=0;
- ptt_(&m_pttPort,&itx,&iptt); // Lower PTT
+ int itx = 0;
+ int nport = m_pttPortNumber; // the real COM port number
+ ptt_(&nport, &itx, &iptt); // Lower PTT
+ m_pttErrorShown = false;
+
if(!m_txMute) {
soundOutThread.quitExecution=true;\
}
@@ -1735,10 +2389,6 @@ void MainWindow::guiUpdate()
m_wide_graph_window->updateFreqLabel();
- if(m_startAnother) {
- m_startAnother=false;
- on_actionOpen_next_in_directory_triggered();
- }
if(m_modeQ65==0 and m_modeTx=="Q65") on_pbTxMode_clicked();
if(m_modeJT65==0 and m_modeTx=="JT65") on_pbTxMode_clicked();
@@ -1762,7 +2412,7 @@ void MainWindow::guiUpdate()
lab1->setStyleSheet("QLabel{background-color: #ffff33}");
}
char s[37];
- sprintf(s,"Tx: %s",msgsent);
+ snprintf(s, sizeof(s), "Tx: %.32s", msgsent);
lab1->setText(s);
} else if(m_monitoring) {
lab1->setStyleSheet("QLabel{background-color: #00ff00}");
@@ -2001,11 +2651,23 @@ void MainWindow::genStdMsgs(QString rpt) //genStdMsgs()
ui->txrb1->setChecked(true);
}
+QString MainWindow::call3Path() const
+{
+ QString writablePath = QDir {m_dataDir}.absoluteFilePath("CALL3.TXT");
+ if (!QFile::exists(writablePath)) {
+ QString bundledPath = QDir {m_appDir}.absoluteFilePath("CALL3.TXT");
+ if (QFile::exists(bundledPath)) {
+ QFile::copy(bundledPath, writablePath);
+ }
+ }
+ return writablePath;
+}
+
void MainWindow::lookup() //lookup()
{
QString hiscall=ui->dxCallEntry->text().toUpper().trimmed();
ui->dxCallEntry->setText(hiscall);
- QString call3File = m_appDir + "/CALL3.TXT";
+ QString call3File = call3Path();
QFile f(call3File);
if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
msgBox("Cannot open " + call3File);
@@ -2060,7 +2722,7 @@ void MainWindow::on_addButton_clicked() //Add button
} else {
newEntry += ",,,";
}
- QString call3File = m_appDir + "/CALL3.TXT";
+ QString call3File = call3Path();
QFile f1(call3File);
if(!f1.open(QIODevice::ReadWrite | QIODevice::Text)) {
msgBox("Cannot open " + call3File);
@@ -2079,7 +2741,7 @@ void MainWindow::on_addButton_clicked() //Add button
f1.seek (0);
}
- QString tmpFile = m_appDir + "/CALL3.TMP";
+ QString tmpFile = QDir {m_dataDir}.absoluteFilePath("CALL3.TMP");
QFile f2(tmpFile);
if(!f2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
msgBox("Cannot open " + tmpFile);
@@ -2122,12 +2784,12 @@ void MainWindow::on_addButton_clicked() //Add button
}
if(m_call3Modified) {
- auto const& old_path = m_appDir + "/CALL3.OLD";
+ auto const& old_path = QDir {m_dataDir}.absoluteFilePath("CALL3.OLD");
QFile f0 {old_path};
if (f0.exists ()) f0.remove ();
f1.copy (old_path); // copying as we want to preserve
// symlinks
- f1.open (QFile::WriteOnly | QFile::Text); // truncates
+ qDebug() << "MainWindow::on_addButton_clicked File open result:" << f1.open (QFileDevice::WriteOnly | QFileDevice::Text); // truncates
f2.seek (0);
f1.write (f2.readAll ()); // copy contents
f2.remove ();
@@ -2240,7 +2902,7 @@ void MainWindow::on_genStdMsgsPushButton_clicked() //genStdMsgs button
void MainWindow::on_logQSOButton_clicked() //Log QSO button
{
- int nMHz=int(datcom_.fcenter);
+ int nMHz=getFcenter();
QDateTime t = QDateTime::currentDateTimeUtc();
QString qsoMode=lab5->text();
if(m_modeTx.startsWith("Q65")) qsoMode=lab6->text();
@@ -2301,7 +2963,6 @@ void MainWindow::on_actionJT65A_triggered()
m_mode="JT65A";
m_modeJT65=1;
m_mode65=1;
- m_modeJT65=1;
m_TRperiod=60;
soundInThread.setPeriod(m_TRperiod);
soundOutThread.setPeriod(m_TRperiod);
@@ -2317,7 +2978,6 @@ void MainWindow::on_actionJT65B_triggered()
m_mode="JT65B";
m_modeJT65=2;
m_mode65=2;
- m_modeJT65=2;
m_TRperiod=60;
soundInThread.setPeriod(m_TRperiod);
soundOutThread.setPeriod(m_TRperiod);
@@ -2415,13 +3075,17 @@ void MainWindow::on_actionFUNcube_Dongle_triggered()
void MainWindow::on_actionEdit_wsjt_log_triggered()
{
- proc_editor.start (QDir::toNativeSeparators (m_editorCommand), {QDir::toNativeSeparators (m_appDir + "/wsjt.log"), });
+ proc_editor.start (QDir::toNativeSeparators (m_editorCommand),
+ {QDir::toNativeSeparators (QDir {m_dataDir}.absoluteFilePath ("wsjt.log")), });
}
void MainWindow::on_actionTx_Tune_triggered()
{
- if(g_pTxTune==NULL) {
+ if (!g_pTxTune) {
g_pTxTune = new TxTune(0);
+
+ if (!g_TxTuneGeometry.isEmpty())
+ g_pTxTune->restoreGeometry(g_TxTuneGeometry);
}
g_pTxTune->set_iqAmp(iqAmp);
g_pTxTune->set_iqPhase(iqPhase);
@@ -2457,7 +3121,7 @@ void MainWindow::read_log()
// Update "m_worked" by reading wsjtx.log
m_worked.clear(); //Start from scratch
QFile f("wsjtx.log");
- f.open(QIODevice::ReadOnly);
+// qDebug() << "MainWindow::read_log File open result:" << f.open(QFileDevice::ReadOnly);
if(f.isOpen()) {
QTextStream in(&f);
QString line,callsign;
@@ -2472,3 +3136,8 @@ void MainWindow::read_log()
f.close();
}
}
+
+void pa_deinit()
+{
+ Pa_Terminate();
+}